-->
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 bidirectional problem
PostPosted: Sat Feb 23, 2008 11:28 pm 
Newbie

Joined: Sat Feb 23, 2008 11:00 pm
Posts: 3
Ok, sorry for asking this question but I never did a bidirectional many-to-one, and the only thing I know is I need put the inverse on the many =p

I already made it work with a unidirectional and I discovered after the project already started I needed it bidirectional, I have a scheme on visio of what is need, and I am here asking for a help making it works.

Here is the image
Image

and the code I have so far

Type Class
Code:
   
public class Type{
    private Long ID;
    private String TYPE_NAME;
    private String TYPE_COLOR;
    private String TYPE_PICTURE;
    private boolean TYPE_VISIBLE;
    private Set news = new HashSet();
   
    (Sets and Gets)(...)


Type Hibernate XML
Code:

<hibernate-mapping>
   
    <class name="projects.news.Type" table="TB_NEWS_TYPE">
        <id name="ID" column="ID">
            <generator class="native"/>
        </id>

        <property name="TYPE_NAME" not-null="true" length="255" unique="true"/>
        <property name="TYPE_COLOR" not-null="true" length="255"/>
        <property name="TYPE_PICTURE" not-null="true" length="255"/>
        <property name="TYPE_VISIBLE" not-null="true" type="java.lang.Boolean"/>
       
        <set name="news" table="TB_NEWS">
            <key column="NEWS_TYPE"/>
            <one-to-many class="projects.news.News"/>
        </set>       
       
    </class>
   
</hibernate-mapping>


News Class
Code:
public class News{   
    private Long ID;
    private Long NEWS_TYPE;
    private String NEWS_TITLE;   
    private String NEWS_DESC;   
    private Date NEWS_DATE;   
    private String NEWS_AUTHOR;   
    private Long PROJECT_ID;   
    private Set comments = new HashSet();

        (Sets and Gets)(...)


News Hibernate XML
Code:
<hibernate-mapping>
   
    <class name="projects.news.News" table="TB_NEWS">
        <id name="ID" column="ID">
            <generator class="native"/>
        </id>

        <property name="NEWS_TYPE"/>
        <property name="NEWS_TITLE" not-null="true" length="255"/>
        <property name="NEWS_DESC" not-null="true" length="65535"/>
        <property name="NEWS_DATE" not-null="true" type="timestamp"/>
        <property name="NEWS_AUTHOR" length="255"/>
        <property name="PROJECT_ID" not-null="true"/>
       
        <set name="comments" table="TB_NEWS_COMMENTS">
            <key column="NEWS_ID"/>
            <one-to-many class="projects.news.NewsComments"/>
        </set>       
       
    </class>
   
</hibernate-mapping>


What I need change to make it works bidirectional with the type table

Thank you


Top
 Profile  
 
 Post subject: bidirectional ManyToOne Association
PostPosted: Fri Feb 29, 2008 5:18 am 
Newbie

Joined: Fri Feb 29, 2008 3:37 am
Posts: 3
Hi TLP,
I'm using Annotation for mapping, there you would need mappedBy. I think the XML-equipollant ist invers=true. Do you have Gavin King's JAVA PERSISTENCE with HIBERNATE? Look at Cap. 6.4.3.
Regards
AWi


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 29, 2008 5:30 am 
Regular
Regular

Joined: Wed Jun 20, 2007 1:53 am
Posts: 75
User below mapping in your News hbm.

<many-to-one
name="type"
column="NEWS_ID"
entity-name="packagename.Type"/>


Regards
Shanmugam.N


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.