• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Emulate @OneToMany association without adding a new Persistent Class

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

is there anyway through annotations to create a list of arbitrary size to be bound to a persistent class, in such a way that it's not necessary to create an additional class?
Let me pose a short example:

Class A holds a list of "references" to Class B at running time.

Class B has no idea about A, and doesn't need to.

But somewhere I need to recall which references of B are bound to an instance of A.

Normally I would do this creating an intermediary persistent class, let's call it AB, where I would store a reference to both A and B, and would make AB persistent aswell. However if possible since I have to recall those values only at one very specific point of my application, I prefer to avoid creating the intermediary class and let's say store the ids Integer references of B in a persistent member of A, which at running time would be converted in a List with references to instances of class B.

Is that possible?

Manny thanks,

Carlos.
 
Carlos Conti
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well,

in the meantime until someone figures out a better way, what I do is to virtually load/unload/edit a separate @Transient field of type ArrayList, where I update the references upon update of the string member that holds the list of Integer ids, separated by semicolons.

Regards,

Carlos.
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post a code sample? It should be trivial to get the list of B from A if you are using JPA/Hibernate without using a relationship class or Transient. Maybe I am misunderstanding the problem. Posting a code sample would help
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I haven't misunderstood your problem, I think you are looking for a one to many unidirectional relationship without using an intermediate class as well without an intermediate table in the database?? Assuming that is right,here is an example that provides you a solution

JPA Wiki
 
It's exactly the same and completely different as this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic