-->
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: new instance of a class with a many-to-one association
PostPosted: Wed Oct 13, 2004 2:42 pm 
Newbie

Joined: Mon Jun 14, 2004 5:16 pm
Posts: 16
Location: New York
Hibernate version: 2.1

Given the following class:
Code:
public class Building implements Serializable{
      private Integer id;
      private String name;
      private Type type;
       ....
}


where Type is defined as
Code:
public class Type implements Serializable{
      private Integer id;
      private String name;
       .....

      public Type(Integer id){
           this.id = id;
       }
}


I want to create a new Building instance given an input form..Can I do the following to set its Type object:
Code:
public Building(BuildingForm form){
       name = form.getName();

     
      //assuming that a Type instance with form.getTypeId() already
      //exists in the database.
      type = new Type(form.getTypeId());
     
}


I think the other, and probably better, way of accomplishing the same thing would be to retrieve the Type object with form.getTypeId() and set it that way. Is this way definitely wrong?

Thanks,
Cagan


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.