File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Composite PK AutoIncrement?

Vamshi Bhoopalam

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.
colB VARCHAR(50),

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

How do i specify an autoincrement on colA?

Any help would be appreciated.

Thanks in advance.
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 661

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

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.

jQuery in Action, 3rd edition
subject: Composite PK AutoIncrement?
jQuery in Action, 3rd edition