Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when "@ManyToOne " with "PK Auto generation" #313

Closed
jinagko opened this issue Jun 27, 2013 · 10 comments
Closed

when "@ManyToOne " with "PK Auto generation" #313

jinagko opened this issue Jun 27, 2013 · 10 comments

Comments

@jinagko
Copy link

jinagko commented Jun 27, 2013

I had use two Entites with "PK Auto generation"
1.Yh_info Entity


@Id
@Column(name = "UserID")
@TableGenerator(name = "id_gen", allocationSize = 1, initialValue = 1)
@GeneratedValue(generator = "id_gen", strategy = GenerationType.TABLE)
private Long userid;
......
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "regionid")
private Jg_region jg_region;
......

2.Jg_region Entity


@Id
@Column(name = "RegionID")
@TableGenerator(name = "id_gen", allocationSize = 1, initialValue = 1)
@GeneratedValue(generator = "id_gen", strategy = GenerationType.TABLE)
private Long regionid;
.....

problems:
when I create new Object Yh_info

Yh_info yh_info = new Yh_info();
Jg_region jg_region = new Jg_region();
jg_region.setRegionid(1);
yh_info.setJg_region(jg_regionid);
em.persist(yh_info);
 

when I run this tiwce or more, I expected the "regionid" is "1",but the new Yh_info.Jg_region.regionid is increase
;
It means I assign the regionid value is "1" , but it auto increase to "2";

Maybe it means what I want to express.
In this, "empAdr_result " should have merge in Address Equals 1 ; but when EmployeeInfo is persisted ,EmployeeAddress persist too;

 EmployeeAddress address_info = new EmployeeAddress();
        address_info.setStreet("street");
    em.persist(address_info);
    EmployeeAddress empAdr_result = em.find(EmployeeAddress.class, 1l);
    Assert.assertEquals("1", empAdr_result.getAddress().toString());

```
EmployeeInfo emp_info = new EmployeeInfo();
emp_info.setAddress(empAdr_result);
    em.persist(emp_info);
empAdr_result = em.find(EmployeeAddress.class, 2l);
Assert.assertEquals("1", empAdr_result.getAddress().toString());
Assert.assertEquals("2", empAdr_result.getAddress().toString());

I guest it is persist(jg_region) every times;I just want to merge(jg_region) ;

I means it should not have generate a new EmployeeAddress which Address Equals 2 , it should have always merge into EmployeeAddress which Address Equals 1;

<pre><code>
 EmployeeInfo emp_info_result =  em.find(EmployeeInfo .class, 1l);
Assert.assertEquals("1", emp_info_result .getAddress().getAddress().toString());
Assert.assertEquals("2", emp_info_result .getAddress().getAddress().toString());</code></pre>


It's so kind of your to read this,Could you give me a help~ 
@mevivs
Copy link
Collaborator

mevivs commented Jun 27, 2013

Could you please describe issues which you are getting into?

-Vivek

@jinagko
Copy link
Author

jinagko commented Jun 27, 2013

I'm sorry,accident Enter BUTTON,editing NOW!

@mevivs
Copy link
Collaborator

mevivs commented Jun 27, 2013

Any entity containing only row key will not get persisted in Cassandra. Cassandra does not allows this.
Jg_region Entity is containing any other non row key column?

-Vivek

@mevivs
Copy link
Collaborator

mevivs commented Jun 27, 2013

Jg_region must contain a non row key column, hence it will not get persisted. As Cassandra does not store it down with row key value only.

-Vivek

@jinagko
Copy link
Author

jinagko commented Jun 27, 2013

I have other colunn; the problem is I expect meger the jg_region in id=1 ; but it persist a new object

@mevivs
Copy link
Collaborator

mevivs commented Jun 27, 2013

Hi,

I have other colunn; the problem is I expect meger the jg_region in id=1 ; but it persist a new object

Can you please elaborate more on this?

Also, as per

Yh_info yh_info = new Yh_info();
Jg_region jg_region = new Jg_region();
jg_region.setRegionid(1);
yh_info.setJg_region(jg_regionid);
em.persist(yh_info);

i can't see adding any non row key column in "jg_region" entity.
-Vivek

mevivs added a commit that referenced this issue Jun 27, 2013
@mevivs
Copy link
Collaborator

mevivs commented Jun 27, 2013

@jinagko
Copy link
Author

jinagko commented Jun 27, 2013

Hi,
forgive my poor English~

I have been off work,I type this code in Text-Editor;

Maybe it means what I want to express.
In this, "empAdr_result " should have merge in Address Equals 1 ; but when EmployeeInfo is persisted ,EmployeeAddress persist too;

   EmployeeAddress address_info = new EmployeeAddress();
        address_info.setStreet("street");
    em.persist(address_info);
    EmployeeAddress empAdr_result = em.find(EmployeeAddress.class, 1l);
    Assert.assertEquals("1", empAdr_result.getAddress().toString());
    EmployeeInfo emp_info = new EmployeeInfo();
    emp_info.setAddress(empAdr_result);
        em.persist(emp_info);
    empAdr_result = em.find(EmployeeAddress.class, 2l);
    Assert.assertEquals("1", empAdr_result.getAddress().toString());
    Assert.assertEquals("2", empAdr_result.getAddress().toString());

@jinagko
Copy link
Author

jinagko commented Jun 27, 2013

I means it should not have generate a new EmployeeAddress which Address Equals 2 , it should have always merge into EmployeeAddress which Address Equals 1;

 EmployeeInfo emp_info_result =  em.find(EmployeeInfo .class, 1l);
Assert.assertEquals("1", emp_info_result .getAddress().getAddress().toString());
Assert.assertEquals("2", emp_info_result .getAddress().getAddress().toString());

@mevivs
Copy link
Collaborator

mevivs commented Jul 6, 2013

Fixed and releasing with 2.6. Please verify.
-Vivek

@jinagko jinagko closed this as completed Jul 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants