File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@OneToMany return objects with the same reference

 
Mohammad wish
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Professional,
i have an Entity which have the parentAccount @OneToMany attribute (it is a foreign Key to the primary key )

public class AccountBean implements Serializable{

@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "accountGenerator")
@Column(name = "ID")
private Integer id;

@Column(name = "NAME_AR", length = 100, unique = false)
private String nameAr;

@ManyToOne
@JoinColumn(name = "LEVEL_ID",nullable = false, referencedColumnName = "ID")
private LevelBean level;

@ManyToOne
@JoinColumn(name = "PARENT_ACCOUNT_ID",nullable = true, referencedColumnName = "ID")
private AccountBean parentAccount;


execute JPA query to get all accounts , i notice that all parentAccount object is reference to the same object for all accounts that have same parent account i.e ( i have 3 accounts and all of them have the same parent account object , in the memory the 3 accounts reference the same parent account object in the memory )

the problem is if in my screen once i changed the parent account of one of the 3 account the other parent account changed for the other accounts (because they are reference to the same object in the memory ), how can i solve the problem.

Regards
Wish79
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i notice that all parentAccount object is reference to the same object for all accounts that have same parent account

That would be the expected behaviour, why would you expect something different?
 
Mohammad wish
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know but my screen submit all records so when I changed one of them the others ( which have the same parent account reference object ) changed , the expected behavior should changed just the changed record not all
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you have changed the one and only parent record. You would want all child records to see the update surely?
 
Mohammad wish
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want just the changed record to be affected , and the other records still have the old value not new one
 
Mohammad wish
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i solved the problem by setting the parentaccount object to null, then update it.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic