-->
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: one to many mapping problem..
PostPosted: Wed Aug 26, 2009 4:22 am 
Newbie

Joined: Wed Aug 26, 2009 3:29 am
Posts: 5
Hi, im trying to create two object and having one to many relationship. I have successfully created
the two object which replica and replicate tables.

The problem is when i put values on sample data to test if it will link my replica_table to its parent replica object. I'm getting an empty value.

replica object is the parent .
replica_table object is the child.

--replica_table--
id description name parentReplica_001
1 replica_table test_001 desc 1 replica_table name 1 <--- empty value here
2 replica_table test_001 desc 2 replica_table name 2 <--- empty value here


im expecting values in mysql like this one.

--replica_table--
id description name parentReplica_001
1 replica_table test_001 desc 1 replica_table name 1 2
2 replica_table test_001 desc 2 replica_table name 2 2


Below is my code..

----------------------------- Replica
Code:
@Entity @Table(name="replica")
public class Replica extends BaseObject {
    private Long id;
    private String name;
    private String description;
   
    public Replica() {}
   
    @Id @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name="name", length=50)
    public String getName() {
        return name;
    }

        public void setName(String name) {
        this.name = name;
    }
   
    @Column(name="description", length=50)
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
   
    @OneToMany (mappedBy="parentReplica_001")
    private Set<ReplicaTables> replica_tables = new HashSet();

    etc...


-----------------------------


----------------------------- Replica table object
Code:
@Entity @Table(name="replica_tables")
public class ReplicaTables extends BaseObject {
    private Long id;
    private String name;
    private String description;

    public ReplicaTables() {}
   

    @Column(name="name", length=50)
    public String getName() {
        return name;
    }

        public void setName(String name) {
        this.name = name;
    }
   
    @Column(name="description", length=50)
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
   
    @Id @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @ManyToOne
    @JoinColumn (name="ParentReplica_id_001", updatable = false, insertable = false)
    private Replica parentReplica_001;


etc . . .
--------------------------------

------------------------------- sample-data.xml

Code:
       <table name="replica">
        <column>id</column>
                <column>name</column>
        <column>description</column>
        <row>
            <value description="id">1</value>
                        <value description="name">replica name 1</value>
            <value description="description">replica desc 1</value>
        </row>
        <row>
            <value description="id">2</value>
            <value description="name">replicate name 2</value>
            <value description="description">replicate desc 2</value>
        </row>
    </table>
   
    <table name="replica_tables">
        <column>id</column>
                <column>name</column>
        <column>description</column>
        <column>parentReplica_001</column>
        <row>
            <value description="id">1</value>
                        <value description="name">replica_table name 1</value>
            <value description="description">replica_table test_001 desc 1</value>
             <value description="parentReplica_001">2</value>
        </row>
        <row>
            <value description="id">2</value>
            <value description="name">replicate_table2 name 2</value>
            <value description="description">replicate_table2 desc 2</value>
            <value description="parentReplica_001">2</value>
        </row>
    </table>

----------------------------

Can anyone help me determine why the parenReplica_001 is empty? thanks..


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.