Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Constructing value objects using HQL or Creteria

 
Vidyasagar Guduru
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose there are three non related entity classes A, B and C mapped into DB using Hibernate.

There is a requirement to build a value object called V and it needs few properties (columns) from A, few from B and few from C.

Now how I can construct the object of V using HQL or Criteria instead of using native SQL or reading the individual objects A, B, C separately and setting the values of V.

Thanks in advance for your inputs.
 
Javid Jamae
Author
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not create a new class V with its own mapping that points to the columns that you need in the tables that A, B, and C are mapped to?
 
Vidyasagar Guduru
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the reply,

How I can map the V to the selected columns of A,B,C.
V is not a domain object I thought it is not supposed to load or store any entity data from the DB.

 
Javid Jamae
Author
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to create V using HQL or Criteria, wouldn't you have to have V mapped to the database anyways? I guess I'm not quite following what you're trying to do.

What is the underlying technical constraint you have? What are you trying to accomplish? Are you trying to use V as a data transfer object?

When you detach an object from a Hibernate session, it is no longer associated with a persistence context. Therefore, you can pass that object around (even serialize it and send it across a wire) and then reattach it later if you need to.
 
Mohit Malik
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the Entities are Non related then why do you want there fields in a single value object(DTO)?

Here is a sample code for An entity

  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic