-->
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.  [ 3 posts ] 
Author Message
 Post subject: Many-to-one mapping, value not object reference
PostPosted: Thu Jan 03, 2008 10:10 am 
Newbie

Joined: Thu Jan 03, 2008 9:53 am
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3

Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Hi,
I've just started trying to develop a new part of our application in hibernate..

I'd quite like to have a many-to-one mapping in which the reference is just an ID (integer/String) rather than a full blown object..is there any way this is possible?

for example, I have a class Script, and a class State..I want each State object to have a reference to the id of a Script object, rather than a reference to a Script object itself...is this do-able?

Code:
public class Script {
     private long id;
     private String name;
     private String code;

     //getters and setters
}

public class State {
    private long scriptId;
    private String [] outputs;

    //getters and setters
}


Many thanks,
Rohit


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 03, 2008 11:31 am 
Regular
Regular

Joined: Sat Nov 25, 2006 11:37 am
Posts: 72
By simply not declaring the relationship you get the plain scriptId property in the State entity.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 03, 2008 11:38 am 
Newbie

Joined: Thu Jan 03, 2008 9:53 am
Posts: 2
ah yes I think I see - when I want to link these 2, i can just use
Code:
int scriptId = myScript.getId();
myState.setScriptId(scriptId);


The relationship isn't there in the object, but when I persist the 2 objects it will be maintained in the database right?

Ro


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

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.