-->
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.  [ 4 posts ] 
Author Message
 Post subject: Mapping without creating objects for each table?
PostPosted: Thu Jul 21, 2005 1:20 pm 
Newbie

Joined: Wed Jul 20, 2005 7:59 pm
Posts: 3
I am making a database service that allows users to save favorite information. Several of our projects will be using this service, so each favorite needs a property to identify what project it is for. Here is the java class:

public class Favorite {
private Integer id;
private Integer uid;
private String category;
private String project; <--- project name
private Integer maxElements;
private Date creationTimestamp;
private List elements;

...methods...
}

I want to keep our database normalized so the favorite table has a project_id key that references the project table, whose only columns are id and name. Is there any way I can map the project name directly to the Favorite class without creating a Project class that only contains an id and name property? Can this be done with UserType?

Hibernate version:
2.1
Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:
MySQL 4.0.22
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 1:24 pm 
Senior
Senior

Joined: Thu May 12, 2005 11:40 pm
Posts: 125
Location: Canada
You can do it with <join>, but this is not a good idea from a design standpoint. It makes your application much more difficult to extend.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 1:50 pm 
Newbie

Joined: Wed Jul 20, 2005 7:59 pm
Posts: 3
Thanks for the response. I do not think I can use <join> as it is in v3.0, and I am here with 2.1. It seems that a many-to-one would be more appropriate anyway. Is it possible to make a UserType that can take the id and name from the referenced table and make it into a string for my favorite class?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 2:01 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
jmendonca wrote:
Thanks for the response. I do not think I can use <join> as it is in v3.0, and I am here with 2.1. It seems that a many-to-one would be more appropriate anyway. Is it possible to make a UserType that can take the id and name from the referenced table and make it into a string for my favorite class?


I'm not sure about the UserType but you can map it as a m2o and just have your set method take the string from the aggregate object and store it in the project attribute.

Your POJO doesn't have to have attributes for each mapped field, just getters/setters for each one.

Be sure and specify cascade="none" so that there is no attempt to update the Project table.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.