• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

@OneToMany return objects with the same reference

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i solved the problem by setting the parentaccount object to null, then update it.
 
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic