-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Is it possible to map a FK column as an id property ?
PostPosted: Sun Apr 06, 2008 7:12 am 
Newbie

Joined: Sun Apr 06, 2008 6:38 am
Posts: 4
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 is that most of the our Java code only cares about the integer code, and we prefer to manipulate these codes directly rather than always play around with Reason objects. We need the FK just to make sure values are valid)

I could avoid @ManyToOne altogether, and use a simple @Column instead, but then I lose the foreign key definition in the database (since I use hibernate ant tasks to create the tables...)

I tried changing the member to int (and Integer) type in the example above and got a runtime exception (PropertyAccessException) when trying to save() an object.

Any ideas?
Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.