primary key « Map « JPA Q&A





1. How to map a set of objects in Hibernate without primary keys being equally named?    stackoverflow.com

I have a domain object class that represents a table. This class has an association to another table, but the source class' property is not named the same as the ...

2. Hibernate one to many using something other than a primary key    stackoverflow.com

I have a class A that has a set of B's. However, these two objects are linked by fields that are NOT the primary key. For B, I can use , but ...

3. using a Map to create primary keys using Hibernate Annotations    stackoverflow.com

I'm not too used to ORM mapping, having come from a PHP background. I'm trying to achieve a link between a series of questions and their possible answers, along with the ...

4. Mapping a Natural Key with Hibernate Annotations    stackoverflow.com

I have a legacy table that uses a column that holds a date as the natural prmary key to the table. I am trying to map this with hibernate, but for ...

5. JPA Entity Foreign Keys mapped to a Primary Key    stackoverflow.com

Is it possible for a Primary Key of an nested Entity to be used as the Primary Key of the Nest Entity? For Example: If I had a Entity 'Staff' who ...

6. Mapping issue with multi-field primary keys using hibernate/JPA annotations    stackoverflow.com

I'm stuck with a database which is using multi-field primary keys. I have a situation where I have a master and details table, where the details table's primary key contains fields ...

7. ManyToMany relationship using JPA with Hibernate provider is not creating primary keys    stackoverflow.com

I've created two JPA entities (Client, InstrumentTraded) using Hibernate as a provider that have a ManyToMany relationship. After letting Hibernate generate the tables for MySQL it appears that the ManyToMany ...

8. Hibernate mapping for a table with no primary key    stackoverflow.com

I know this question has been asked before but I have a design question as well. There are two tables like so:

Table Group_table
column pk_Group_name
column group_type
etc

Table Group_members
column fk_group_name -> foreign key to group_table
column ...

9. Using JPA mapped by not primary key field?    stackoverflow.com

I am having troubles getting this working and I wonder if what I am doing simply does not make sense?

public class Application {
    @Id
    @GeneratedValue(strategy ...





10. How to cascade save a simple shared primary key one-to-one mapping in hibernate 3.6    stackoverflow.com

I need a simple hibernate example of an entity with a one-to-one relationship with another entity where they both share the primary key. I need to only have to save ...

11. How to map two foreign keys mapping to the same primary key column in Hibernate (one-to-one)?    stackoverflow.com

I am new to Java and Hibernate and I am trying to map the following scenario in Hibernate (using annotations). I am dealing with the following two tables ( related to some ...

12. hibernate many to many mappings for join table with extra columns , surrogate key, additional primary key    stackoverflow.com

I'm having hard time to resolve entity mappings (using annotations) for the following scenarios ( from legacy db) Scenario 1:

Table A
  A_ID (PK)

Table B    
  B_ID (PK)

TABLE ...

13. mapping two tables with same primary key one to one relationship using annotations    stackoverflow.com

I'm dealing with the following problem, I have two tables (I going to use generic names) Table1, and Table2, two table have the same primary key and exist one to one ...

14. One to one mapping using primary key    stackoverflow.com

I have two simple tables: Item and ItemDetail Table Item has following columns: id, name Table ItemDetail has following columns: itemId, color, size An ItemDetail never exists without an Item. An Item can exist ...

15. hibernate mapping foreign-key within primary key to alternate key    stackoverflow.com

I have 3 tables:

Account
{
Long account_id; // primary key, alternate key field 1
Long client_id;  // alternate key field 2
...
}

Admin
{
Long office_id;  // primary key field 1
Long account_id; // primary key field ...

16. Hibernate Mapping problem because no primary key in database    coderanch.com

Every relational table has a "natural" primary key. However, it may be unrecognized and undefined. The best solution to your problem then is to determine what the primary key is and define it as such in your RDBMS. Having said that, it is better to use a surrogate key for the primary key to protect against business semantics changes in the ...





17. Hibernate: Collection Mapping on Non-Primary Key    coderanch.com

Hi All, I have what I'm sure is a very basic Hibernate Question. I've hunted diligently for an answer and I've come up blank. I thought I'd post my question here as opposed to the hibernate.org forums since you folks tend to be a little kinder to us newbies!! Anyway... How do I map a one-to-many association based on something other ...

18. same primary key as foreign key in two table[Hibernate Mapping]    coderanch.com

Hi All, schema TABLE_A ========= id_a[PK] tx_a_desc TABLE_B ========= id_b[PK] id_a[FK] tx_b_desc TABLE_C ========= id_c id_a[FK] tx_c_desc With id_c and id_a as composite primary key for TABLE_C What should be the best way to map these? Its not normal but I can't change the schema. I am trying something like this for now A.java [@Table(name = "TABLE_A")] @OneToMany(fetch = FetchType.LAZY) @JoinColumn(name ...

19. Primary -Foreign key mapping    forum.hibernate.org

22. How to map to a table which is not having a primary key    forum.hibernate.org

How can I map a table (or view) with no primary key? Every table (or even view) should have some unique key. The mathematical definition of a relation is a set of tuples. (Sets do not permit duplicate elements.) Furthermore, truly identical rows can not possibly have any meaningful semantics from the user's perspective. In some cases it may be sensible ...

24. Primary Key issue in One to many mapping    forum.hibernate.org

26. Hibernate primary key mapping    forum.hibernate.org

Hi, I am using hibernate 3 and trying to retrieve records form contact table and it has first, last name,phno, contactid is key. i have contact.hbm.xml file with all these mappings. i am able to retrive all records using this hbm file. when I want to insert a record in by using the same hbm file (key is auto genrated by ...

27. Map Primary Table With Secondary Table On A Non-Primary Key    forum.hibernate.org

Newbie Joined: Thu Sep 15, 2011 2:59 pm Posts: 1 Hi, I was trying to map a primary table to a secondary table on a non-primary key columns. Hibernate out of the box does not allow it and the documentation says that a primary and secondary table can only be matched on a primary key of both tables. This restricts the ...

28. no-primary-key-table mapping    forum.hibernate.org

Hello, I have a simple question. If I have a table which has no key definition, and if I try to map this, what happens? I mean, can hibernate handle tables without key definition? Actually I already tried such a thing, because I have some tables to map which have no keys, and I am not allowed to change. I could ...

29. Mapping without primary key    forum.hibernate.org

...

30. Primary key required in mapping file ?    forum.hibernate.org

It seems that a primary key is required on every table that is mapped. Not that every table has to have a primary key in the schema itself, but it seems to be required in the mapping file. I need to have a mapping for a particular table without any primary key. Any help would be much appreciated.

31. Mapping not to primary key    forum.hibernate.org

I have the following problem: TABLE A -Primary Key name PkId -A field named hCod not unique -A field name X TABLE B -Primary Key named PkId -A "foreign key" name idA -A field named Y The situation is not the "standard", because there is not foreign key constraint from idA (B) to pkId (A), because in idA of B there ...

32. mapping of tables with no primary key    forum.hibernate.org

33. How do I map this: (collection key != parent primary key)    forum.hibernate.org

Hello! What I want is to map a one-to-many from PARENT to CHILD using collection_id. Judging from previous posts I get the impression this can't be expressed in the mapping, but instead I would need a custom getChildren() method which does a HQL query, it that correct? (This is legacy data) PARENT_TABLE ============ parent_id (PRIMARY KEY) collection_id (UNIQUE) CHILD_TABLE =========== child_id ...

34. How to map a table without primary key    forum.hibernate.org

35. not auto generating primary key mapping error    forum.hibernate.org

hi i have database table called users. It is used for user loggings to the system It contains these fields. LogonID varchar(20) primary key Name varchar(40) Password varchar(20) EmailAddress varchar(20) LastLogon datetime but this table does not contain any auto generatiing PK, when i am going to map this angd trying to login to the syatem following errors occurs. What i ...

36. Error:mapping multiple foreign to the same primary key    forum.hibernate.org

There are 2 tables: order and profile In table Order: there are 3 fields that has reference to table profile. How should I define the mapping in this situation. I recieved a runtime error: net.sf.hibernate.MappingException: Foreign key (ORDERTABLE [SHIPPING_PROFILE_ID_FK,BILLING_PROFILE_ID_FK,ORIGINATOR_PROFILE_ID_FK])) must have same number of columns as the referenced primary key (PROFILE [PROFILE_ID]) Here are the 2 hbm.xml files:

37. Mapping my own "id" (primary key) which is defined    forum.hibernate.org

I am (trying to) migrating my project over to Hibernate and need to preserve the installed base (which is working fine). I suppose I will take your advice, but at this time I would like to query with the keys I have in place. Is this possible to do, with an I to migrate it to a Hibernate generated key? TIA ...

38. Mapping across 1-1 table with no primary key in 2nd table    forum.hibernate.org

Hello, I'm new to hibernate and am fast becoming a big fan. I have just convinced a a client to use it after a big POC shootout between toplink, JDO and Hibernate. Now I have questions! The project is an oracle 9i database that we have little control over. There are two tables in the db which should be one, but ...

39. Can I map a table without primary key ?    forum.hibernate.org

40. Inheritance and primary keys    forum.hibernate.org

The database I have to work with has defined primary keys on virtually every table, but ideally I would like to implement some inheritance at the object layer. e.g. The database defines an asset with a primary key, a contract which is an asset has it's own primary key and a clientContract which is an contract has it's own primary key. ...

41. HowTo Map a table whose Primary key consists of 2 columns???    forum.hibernate.org

Hi, I am a complete Newbie to Hibernate and my problem is the following. I do not know howto correctly map a table whose primary key consists of two columns....The other question is more general. Is it better to generate the DDL for the databases before doing the hibernate-mappings or should one design the database tables on the basis of the ...

42. Many-to-Many : mapping without Primary Key class?    forum.hibernate.org

Hibernate version:2.1.7c [Name and version of the database you are using:Oracle 8 I have the following senario and need comments about the mappings: Quote: ITEM (ITEM_ID, NAME) ORDER (ORDER_ID, DESCRIPTION) ORDER_ITEM (ITEM_ID, ORDER_ID, QTY,PRICE) My Order.hbm.xml is as follows: Code: ...

43. Many-to-Many : mapping without Primary Key class?    forum.hibernate.org

Hibernate version:2.1.7c [Name and version of the database :Oracle 8 I have the following senario and need comments about the mappings: Quote: ITEM (ITEM_ID, NAME) ORDER (ORDER_ID, DESCRIPTION) ORDER_ITEM (ITEM_ID, ORDER_ID, QTY,PRICE) My Order.hbm.xml is as follows: Code: ...

44. Error on mapping primary/foreign keys    forum.hibernate.org

I'm trying to map a simple many-to-one. Similar mappings I've done many times before but this one is driving me mad..... When Hibernate starts it tells me Quote: net.sf.hibernate.MappingException: Foreign key (clips [link_id])) must have same number of columns as the referenced primary key (links [link_cona_id,link_elr_name]) The foreign key for clips is OK - link_id but the primary key for links ...

45. Reg. Primary Key Mapping    forum.hibernate.org

46. general: OR mapping in hibernate for composit primary keys    forum.hibernate.org

Hi forum, I am new to hibernate and want to port an application which works fine in EJB 2.1/ CMP. I browsed the documentation about compound-id and compound-index and the forum, but found nothing that could bring enlightment. The scenario is like the following: Three tables language, company and employee which have composite keys. I want to map this relational tables ...

48. Mapping an object without primary key    forum.hibernate.org

Hibernate version: 2.1.7 Hello, I'm trying to map an oracle view to a persistent java object. So there is no real primary key. I still have a functionnal one I can use but I would prefer not to since I don't need it (an also, there would be a component in it which is not accepted in a composite id so ...

49. Mapping primary key and foreign key    forum.hibernate.org

Hi All I am very new to hibernate and little confused about primary key and foreignkey in .hbm.xml file. Lets say I have a table called , User which has following fields ID (Primary key) User name Password I have another table called User_Details User_Details ID (PK+Foreign key to user table) First Name Last Name Address City Country Now I want ...

50. Problem with Primary key & Foreign Key mapping    forum.hibernate.org

51. Trying to map many-to-one without using primary key    forum.hibernate.org

Newbie Joined: Fri Aug 05, 2005 5:37 pm Posts: 2 I am trying to map between two objects, CommunicationRecord and OutputType The primary key for OutputType is outputIdn (Integer) and effectiveDate (Date). There is a column on CommunicationRecord called outputIdn that can be joined to OutputType provided that you specify the following conditions on OutputType (effectiveDate <= sysdate and cancelDate > ...

52. one-to-one mapping with different primary keys    forum.hibernate.org

But how can we do this with annotation ? I am using the hibernate annotation documentation that says to do this : Code: @Entity public class Body { @Id public Long getId() { return id; } @OneToOne(cascade = CascadeType.ALL) @PrimaryKeyJoinColumn public ...

53. How to map a primary key that's not in the java classes?    forum.hibernate.org

Hello everybody, I've searched through the forum and some books but i can not find any answers to my question. My problem is about many-to-many relationships which the relationship table has another primary key (other than the foreign keys) and if this primary key can not be mapped from java classes. (It's a key that's automatically given depending on the composite ...

54. how to map a foreign key which combines two primary keys    forum.hibernate.org

Hi folks, I have three classes: Survey.java, Question.java and Answer.java. The multiplicity between Survey.java and Question.java is many-to-many. The ANSWER table should has its own primary key, and there should also be a foreign key (or two?) which combines the primary keys of table SURVEY (SURVEY_ID) and QUESTION (QUESTION_ID). The table SURVEY_QUESTION will be automatically created since I declared it in ...

55. Mapping a foreign key for more than one primary key    forum.hibernate.org

Hello, I have 4 tables t1,t2,t3 each having 1 column as id and t4 having colum1 and column2 as composite primary key, column1 is a foreign key on t3's primary key, column2 should be a foreign for either t1's primary key or t2's primary key. The actual situation is that column2 is a foreign key for t1's and t2's primary key ...

58. inheritance, primary keys and stored procedures    forum.hibernate.org

Hi! Is it possible to use stored procedures for saving objects, which are part of a class hierarchie? To be more precise, the primary key should be generated by the stored procedure call. But I see no way, how the generated id could be passed from the insert of the parent table to the insert of the child table. But this ...

59. SQL Server2005 creats its own Primary Key...how to map?    forum.hibernate.org

Hi at all, my Subject gives nearly all informations. I am using Hibernate 2 and SQL Server 2005. I wanne map an existing Database wich create its own Primary key. If it wouldnt, i could use to create the key by the mapping file. But in the given situation it doesnt work. im ...

60. how to create a mapping XML file if there is no primary key?    forum.hibernate.org

If it's a "top level" class (one that you'll want to be able to manipulate on its own and not only in a collection) then it needs an id. It doesn't strictly have to be the DB's primary key for the table, but it does have to be unique. You must put a valid id in your mapping. Bags and idbags ...

61. how to define a mapping file if there is no primary key???    forum.hibernate.org

gopal wrote: I have a database table which dont have a primary key .It has only foreign key. so how to define a xml mapping file for that table. I tried giving foreign key in tag. but when the query executes it returns only one row, eventhough if there are more row exists. Who is managing the constraint ? Hibernate ...

62. Inheritance with a foreign key wich isn't the primary key    forum.hibernate.org

Hello I don't know how to map an inheritance relationship based on a field which is not the primary key of the table of the subclass. For example with the application CaveatEmptor on the inheritance beetween BillingDetails and CreditCard the hbm is : Code:

63. Mapping definition for table with no primary key    forum.hibernate.org

Code:

64. HELP NEEDED.dont know how to map if there is no primary key    forum.hibernate.org

Hi All, I am trying to find a solution for couple of days. mine is not a legacy database. i am using oracle. i have a parent and child table . my child table does not have a primary key. it has only foreign key. So which column you will specify in tag of child hbm file. i specified foriegn ...

65. Inheritance - Base class without primary key    forum.hibernate.org

I'm trying to create a class hierarchy where I stick all common table columns into a base class. So I have a base class called "Auditable" that has "modifyTime" and "modifyUserId" properties. Then I extend that with "Expirable" with properties "validFrom" and "validTo". In the base class mapping, I'm getting an XML validation error (it expects the element, but I ...

68. How can I do a mapping for Table without primary Key ?    forum.hibernate.org

Hello, I have tables in an existing DB wich don't have primary key, they do links between many tables with Foreign Keys nullable and others attributes. there is just constraints (indexes) on these tables about the combination of the foreign keys. the problem is to load datas from these tables when I will do a find all ... "from myTable" if ...

69. How to specify a primary key field in a map association    forum.hibernate.org

I have an object that holds a hashmap which maps to a different table. The table has 4 fields, a surrogate PK, the FK and the name and value colums which hold the hashmap data. When hibernate saves I get an error inserting null into the PK field. How would I specify a primary key field in a map subelement? My ...

70. How to map compound primary and foreign keys sharing a field    forum.hibernate.org

Hi! For some reason I need to work with tables with compound keys. The keys have two parts, one is generated by a Postgres sequence (pk) the other is assigned (machine_id). The reason was so that rows generated by different machines can be integrated without conflicts. Now I would like to map a simple one-to-many relationship. For simplicity, let's have two ...

71. Defining/Adding to the primary key of a map    forum.hibernate.org

Is there a way to add to the default primary key definition of a map using a 'unique-key' tag or something of that nature? By default, hibernate uses the 'key' and 'map-key' tags to create the primary key index. I would like to include one additional field in that primary key. For example, I have a class called EAccount that can ...

72. how do i map a many to many on a non primary key column    forum.hibernate.org

all, i have read the documentation but it is not apparant to me how i create a many-to-many relationship on a column other than the primary key. my problem stems from the fact that i am using tomcat container authentication and thus must follow the directions for the tables it needs. so what i have is a user, role and user_role ...

73. Mapping file for existing table - two fields as primary key    forum.hibernate.org

Thanks for the pointer ... I usually work best with good examples which I did not find at that location hence the question. With a bit more reading and trials I found a solution as follows. Advertiser.hbm.xml *************************************** Represents a single Advertiser.

74. How to map relationship as primary key    forum.hibernate.org

Sorry for my bad english. I've two classes: endereco and pessoa There's a one-to-one relationship between both. The primary key of person is transfered to adress as foreign key and it's foreign key is the primary key to. The DDL of tables are the follow: CREATE TABLE pessoa ( CODIGO_PESS NUMBER(6,0) NOT NULL, NOME VARCHAR2(40), TELEFONE VARCHAR2(14), IDADE NUMBER(3,0) ); ALTER ...

75. mapping for table without primary key    forum.hibernate.org

76. Problem with inheritance and primary key in the sub-class    forum.hibernate.org

Need help with Hibernate? Read this first: http://www.hibernate.org/ForumMailingli ... AskForHelp I have create an hierarchy betwen 2 class A and B. It work, the superclass have a primary key. I want to add another attribute in the primary key to the sub class B. A with the primary key id B with the primary key id ( from A) and c ...

77. Mapping a foreign key that doesn't reference a primary key    forum.hibernate.org

@Entity @Table(name = "FOO_DATA") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "TYPE") public abstract class Foo { private Integer id; // primary key private Integer locationId; // corresponding location id, which is also unique ... @Id @Column(name = "PK_OF_FOO") public Integer getId() { return id; } private void setId(Integer id) { this.id = id; } @Column(name ...

78. How to map table without primary key    forum.hibernate.org

I have an Oracle table with the following columns: MODEL_VERSION NUMBER(6) NOT NULL, QKEY VARCHAR2(40) NOT NULL, DISCRIM VARCHAR2(40) NOT NULL, WEIGHT NUMBER(10,2), VALUE NUMBER(10,2), RATING NUMBER(2) NOT NULL, MOD_TIME TIMESTAMP Conceptually, the primary key is a composite, with MODEL_VERSION, QKEY, and VALUE. Unfortunately, I have to allow for VALUE being null. In each group of unique MODEL_VERSION and QKEY, there ...

79. Mapping collection with other property that primary key    forum.hibernate.org

[...] ...

80. Primary key generation based on mapping.    forum.hibernate.org

Hi, Pardon me for reposting this question. I was not really clear in my first post. Following is my Transaction.hbn.xml: Code:

81. Getting a mapping Exception for a primary Key Field    forum.hibernate.org

The problem is resolved as it was else where in the maping. I had a mapping for Address.hbm.xml file, that was responsible for the error. Old map: New Mapping:

82. many-to-many mapping with non-primary key    forum.hibernate.org

I would like to have a many-to-many association between Folder class and Resource class, but not using primary key in Resource table. Unfortunatelly, I have encountered some problems, which i cannot cope with. Would somebody kindly help me? What I would like to do is to let Folder class has the set of Resource classes, and also let Resouce class has ...

83. How do I map a table when the primary key is a foreign key?    forum.hibernate.org

Hello, I used Hibernate tools to map a table from a legacy database. My problem is that the primary key (ao) is also a foreign key, and I don't know how to show this in the xml. This is what I have right now: Code: ...

85. Mapping to a non-primary key of Parent table.    forum.hibernate.org

About this line: Shouldn't it hava a class attribute About the column PERSON_OCC_ID: Is it also a foreign key to table OCCUPATION, or is only a property. In the second case, I think you are comparing an Occupation entity (The property ocupation), to wathever you have in the company table Please, post also the mapping of ...

87. Problem w child foreign key referring to parent primary key    forum.hibernate.org

PROBLEM STATEMENT I am trying to create a parent-child child relationship using hibernate 3.3.1 on MySql 5.0. Parent table has 2 fields ID and Name, ID is integer and the primary key, Name is a VARCHAR (30). Child table has 3 fields, ID, Name, and Parent_Id. ID is integer and the primary key, Name is VARCHAR(30), and Parent_Id is an integer ...

88. in one to may, mapping non primary key as foreign key(need )    forum.hibernate.org

i have two hbm files Group.hbm.xml User.hbm.xml

89. Mapping primary keys    forum.hibernate.org

Hi all, I have designed database with five tables. the fifth table contains all the primary keys of the first for tables as foreign keys. Sample Structure First Table First_Id(Primary Key) First_Name Second Table Second_Id(Primary Key) Second_Name Third Table Third_Id(Primary Key) Third_Name Forth Table Forth_Id(Primary Key) Forth_Name Fifth Table First_Id(Foreign) Second_Id(Foreign) Third_Id(Foreign) Forth_Id(Foreign) Data OtherFields i have wrote all the mapping ...

91. ManyToMany mapping where referencedColumn is non-primary key    forum.hibernate.org

Hi I am trying to specify a ManyToMany mapping annotation through a join table and the join table has a non primary key of the Customer class as one of the column. In the code blow the Customer class has manytomany relation to the CustomerGroup class and in the join table (CUSTOMER_LIST) has the columns : customer_code(non primary key, code property ...

92. Many to one mapping using non primary key    forum.hibernate.org

Hello Everyone, I have a situation. In my project the data model is controlled by business guy and he has created a relationship between two tables where the relationship is with a unique column on other table rather than primary key. Let me create a sample table Table - CATEGORY Column ID - PK Version - CatergoryID - Combination of Version ...

93. Mapping to tables with multiple primary keys    forum.hibernate.org

... ...

94. Many-to-many mapping using non-primary key columns    forum.hibernate.org

Hi guys, I have two tables -- INSTALL_BUILD_RESULTS and BUILD_RESULTS. IBR has a unique column (non-primary key) called Install_Build_Id and BR has a unique column (non-primary key again) called Build_Id. Both are varchars. A third table, LINK_BUILD_TO_INSTALL_BUILD is a table simply consisting of the two columns mentioned above, used together as a composite key. Could somebody check my XMLs for the ...

95. Simple Query:-How do i map two primary keys    forum.hibernate.org

I m using hibernate 3.2.5 I have following problem I have two primary keys in a a table. How do i write a constraints in a mapping file of a table which has got two primary keys.Following is the file ......

96. Problem identifying primary key in mapping file    forum.hibernate.org

I have the following class structure: Code: public class A { private APK pk; public APK getPK() { return pk; } public void setPK(APK pk) { this.pk = pk; } } public ...

97. one-to-many mapping with primary key issue    forum.hibernate.org

Hi all, I have a very frustrating problem i cant get around. I have two table, USERS and REVIEWS. a User can have many reviews. The problem is, when i get a user, i get the following error: Code: java.sql.SQLException: Invalid value for getLong() - '29ab8052-425f-417f-844a-635b1ef1a6a6' com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055) com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926) ...

98. trying to map two primary keys on a table    forum.hibernate.org

...