wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Composite PK AutoIncrement? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Composite PK AutoIncrement?" Watch "Composite PK AutoIncrement?" New topic
Author

Composite PK AutoIncrement?

Vamshi Bhoopalam
Greenhorn

Joined: Jun 02, 2006
Posts: 2
I am trying to write a mapping for the following scenario:

I have a composite PK with one of the column as AutoIncrement.
Example:
colA INT AUTO_INCREMENT,
colB VARCHAR(50),
PrimaryKey(colA,colB).

This is my hibernate mapping:
<composite-id>
<key-property name="colA" type="java.lang.Integer" column="colA"/>
<key-property name="colB" type="java.lang.String" length="50" column="colB"/>
</composite-id>

How do i specify an autoincrement on colA?

Any help would be appreciated.

Thanks in advance.
vamshi
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

Hi,
Welcome to JavaRanch.

In the first place,
why do you have to go for a composite-key, if you have an auto_increment column in your table, which can very well serve the purpose.

You don't have to specify as auto_increment. What you can do do is remove the not-null attribute from the property tag inside comsposite-key and run it as is. Your config file is fine and it would work. You would not get any error while inserting a row.
[ June 04, 2006: Message edited by: Arun Kumarr ]

If you are not laughing at yourself, then you just didn't get the joke.
Vamshi Bhoopalam
Greenhorn

Joined: Jun 02, 2006
Posts: 2
Hi Arun,

Thank you.

My business functionality changed. So i no longer need to put a composite FK. Sorry for the delayed response. I will try out ur solution and reply back to you incase i run into some issues.

regards,
vamshi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Composite PK AutoIncrement?
 
Similar Threads
<join>: <key>: different composite key
Please suggest on this Mapping
Part of Composite-Id is foreign Key:How specify in Mapping?
One-to-many mapping and composite key
Hibernate - Force foreign key lookup on insert