fk « Map « JPA Q&A





1. JPA Cascading Delete: Setting child FK to NULL on a NOT NULL column    stackoverflow.com

I have two tables: t_promo_program and t_promo_program_param. They are represented by the following JPA entities:

@Entity
@Table(name = "t_promo_program")
public class PromoProgram {
  @Id
  @Column(name = "promo_program_id")
  private Long id;

  @OneToMany(cascade ...

2. Hibernate mapping: many to many with fk not having the same name?    stackoverflow.com

I'm trying to map a many-to-many relationship but my middle table is giving me trouble because the names don't match. table1:

**userId**
firstname
lastname
table2:
**user_id** <= fk to table1.userId 
x_id
create_date
table3:
x_id
private1
private2
Could anyone give me a pointer how ...

3. How to delete parent entity and set null in child FK column in hibernate?    stackoverflow.com

Here is example:

@Entity(name="Cat")
public class Cat
{
    @ManyToOne
    @JoinColumn(name="FoodId",nullable=true)
    public Food getFood()
    {
       // code
...
}

@Entity(name="Food")
public ...

4. ManyToOne FK column setting    forum.hibernate.org

Hi, I have a OneToMany relationship between entities Contact and Email. When I create a Contact and add to him 1 or more Email I need to set the FK column in Email table to the right Contact of that email... I tried this: Code: @Entity class Contact{ @Id ...... ...

5. Managing persist with child FK dependence on parent PK    forum.hibernate.org

I'm new to hibernate and trying to navigate some issues. Currently I have multiple tables that contain have a foreign key pointing to the primary key of another table. The primary keys in many cases are auto generated. I'm using MS SQL Server so the database creates the generated key. I'm building the objects up and then performing entityManager.persist on the ...

6. Problem w/ FK Mapping    forum.hibernate.org

I can't figure out what is wrong with my mappings. I'm getting the following Exception: Code: Exception in thread "main" net.sf.hibernate.MappingException: Foreign key must have same number of columns as referenced primary key Start server side stack trace: net.sf.hibernate.MappingException: Foreign key must have same number of columns as referenced primary key at net.sf.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:33) ...

7. child relationship on FK; can't figure the hib option to use    forum.hibernate.org

Using Hibernate 2.1, can't figure out solution to parent-child type scenarion: foo FOO_ID PK bar BAR_ID PK FOO_ID SEQUENCE NAME bar_data FOO_ID DATA There is no PK on bar_data (i know, i know). I'm trying to retrieve all bars, where each bar also contains a Set of bar_data objects based on the FOO_ID FK. Taking the bar_data out of the equation, ...

9. child table column name different from referred fk column    forum.hibernate.org

hi, I am using hibernate 2.1 with sybase. Suppose I have 2 tables,(simplified to a large extent) parent ====== id int name varchar suppose composite key here is (id,name) child ==== child_id int parent_id int (refers id of parent) name varchar suppose composite key here is (child_id,parent_id,name) the mapping snippet for child is,





10. How to map strange PK/FK relationship    forum.hibernate.org

Posting code and XML snippets may make this question harder than it is, so I'll refrain from doing that. Many of the tables in our database have compound primary and foreign keys. And quite often, the primary key contains a foreign key back to another table. This is all fine until the primary key actually contains two foreign keys back to ...

11. mapping related objects NOT using PK's, FK's?    forum.hibernate.org



18. Hibernate setting null in child record's FK before deleting    forum.hibernate.org

Hibernate version: 3.1.2 Mapping documents: [code] [code] Hello there! I have the above mapping in one of my classes. Both Participante and Moderador descend from the same super class Usuario (using a table ...

19. Hibernate mapping FK between Databases    forum.hibernate.org

20. FK violation with element    forum.hibernate.org

Hi everyone, I'm getting an FK violation when trying to insert an entry in a Map, but can't for the life of me figure out why. Could anyone here see what I'm doing wrong? Am I doing something wrong with the tag? Hibernate version: 3.1 Mapping documents: Code: Table structure: create Table Examinator_Kurs (Kurs_ID int not null, Termin_ID int not ...

21. Mapping association defined by (discriminator, FK) pair    forum.hibernate.org

Hi all, Anyone knows if it's possible to map a combination of (discriminator,FK) that joins to different tables/entities depending on the discriminator value. Notice that here discriminator has nothing to do with mapping hierarchies. It's a discriminator just in the sense that it distinguished between different join tables. For example Review with (targetKind, targetId) where targetKind could be Product or Store. ...

23. how to map one-to-many using multi-fields as FK    forum.hibernate.org

I wonder how to map one-to-many with multi-fields as Foreign Key. Suppose there are two tables: Table1( T1F1 NUMBER PRIMARY KEY, T1F2 NUMBER ) Table2( T2F1 NUMBER PRIMARY KEY, T2F2 NUMBER, T2F3 NUMBER ) For Table1, I don't want to use composite key as the primary key. Although T1F2 is not the the PK of Table1, I need to use it ...

24. Is it possible to map a FK column as an id property ?    forum.hibernate.org

Normally, a many-to-one column is mapped to a Java object of the mapped class, for example: Code: @ManyToOne(targetEntity = Reason.class) @JoinColumn(name = "reason_code", nullable = false) private Reason reason; Is there a way to map this column to a simple integer/long Java property containing only the ID of the mapped row? (The reason for this 'strange' question ...

25. FK property on child class in many-to-one    forum.hibernate.org

I have two classes, Parent and Child: Code: public class Parent { private Integer parentId; private List children; public Integer getParentId(){ return this.parentId; } public void setParentId(Integer parentId){ this.parentId = parentId; } public List getChildren() { ...

27. PK/FK mapping issue    forum.hibernate.org

Hi, I have 2 tables with Parent to Child relationship of one to many. Parent (A): col_1 (Generated PK from a sequence) col_2 ... Child (B): col_1 (PK and FK from A) col_3 (PK) col_4 ... I have used cascade="all" in parent After making the object, when i do the saveOrUpdate, the child is getting null value for col_1. I did ...

28. Parent's Composit PK as FK in child shows insert problem    forum.hibernate.org

Hi folks, I am having dificutlies when I insert a new record in child table. actually I have parent table PROFILE which has composite key profile_id and user_id and there is child table EDUCATION which has this composite key as ForeignKey. When I am trying to insert a child record in EDUCATION table its shows error "You have an error in ...

29. Mapping single table with many FK ref to another table    forum.hibernate.org

I have a table that contains contacts (think people) and another table that contains information about a system and who is responsible for aspects of the system (think owner, project manager, sys admin, etc) Each system row has a column for each designated responsibility which holds a Foreign Key reference to the contact tables Primary Key that represents the appropriate contact ...