-->
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.  [ 2 posts ] 
Author Message
 Post subject: hibernate mapping
PostPosted: Tue Feb 05, 2013 3:40 pm 
Beginner
Beginner

Joined: Tue Feb 12, 2008 3:53 pm
Posts: 38
Hi,

I implemented the following mapping

Code:
public class RMessage {
    protected int msgId;

    ..............................

    protected RSubject subject;

    protected Integer subjectId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SUB_ID", updatable = false, insertable = false)
    public RSubject getSubject() {
        return subject;
    }

    public void setSubject(RSubject subject) {
        this.subject = subject;
    }

    @Column(name = "SUB_ID", unique = true, nullable = false, precision = 9, scale = 0, updatable = false, insertable = false)
    public Integer getSubjectId() {
        return subjectId;
    }


as you can see I mapped RMessage with the entity RSubject and subjectId (subjectId is the identifier of RSubject) both corresponding to the column SUB_ID, for development convenience.

I think it is not the best way to proceed but is it an error to do it. In other term, would I encounter stacktrace proceeding this way ?

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: hibernate mapping
PostPosted: Thu Feb 07, 2013 6:00 am 
Beginner
Beginner

Joined: Wed Feb 06, 2013 2:43 am
Posts: 46
I think your getSubject method should be like

@ManyToOne(targetEntity = RSubject.class)
@JoinColumn(name = "SUB_ID", referencedColumnName = "SUB_ID", unique = false, insertable = true, updatable = false, nullable=false)
public RSubject getSubject() {
return subject;
}

It should work for you. and you need to give column names from both the classes and they can be different too.

_________________
Thanks,
Ajit Singh
ajits@mindfiresolutions.com
www.mindfiresolutions.com


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