Hi guys! I have a problem... I have this mapping in my class named FixedItem. And with it is a member named assignedTo which is mapped to an int in a relational table. This is suppose to be a foreign key but I decided not to make it one because I'm not gonna be relating it in the database but instead get its value from a webservice.
Now, I wanted to change the member from an int to a class named Employee which looks like this...
thus, changing the code to
but I don't know where to put the annotations and which mapping to make. The employeeId needs to be the one mapped to the database table field. assigned_to.
If you need to take a look at my FixedItem class and its mapping, here it is...
Sorry for my ignorance, I'm just depending on the netbeans auto-generated code and so are my mappings. Please help me form my annotation and mapping. Thanks! [ May 11, 2007: Message edited by: Timothy Sam ]
Well here is some things, you can have two instance variables for assignedTo,
private int assignedTo;
private Employee assignedEmployee;
Now the assignedTo is still mapped to the int column, because it sounds like you can't change the database.
Now what you will have to do to get the assignedEmployee, is to now look it up.
And to go the other way, you have the assignedEmployee, and call the getId from it to get the value to set assignedTo to.
Personally, If it is a referential integrity need, make the foreign key relationship. You have too many ways to mess up the data if you don't. Then you will only need the @ManyToOne for private Employee assignedTo;
I see your topic has Composition, if it is truely composition, then look at the @Embeddable and @Embedded annotations and see if that is what you are looking for.
Joined: Sep 18, 2005
Hi! Thank you for your suggestion. I'm off the office now so I can't test them yet. Your first suggestion would seem to work. But it sounds like I'll be doing a hack and I'm not a good fan of hacking my own code. Sounds very clever and very tempting though. I will be trying the @Embeddable and @Embedded annotations once I get back to work. I surely hope this could solve my problem.
There is no referential integrity for the assigned_to field by the way... It's just an ordinary int value with no relationship whatsoever. I will be getting its value from a webservice.
Thank you very much for your reply!
subject: Need help with Mapping(Annotation) and Composition