Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it possible to tell Hibernate to modify an existing entity instance

 
Kjeld Sigtermans
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Let's say I have a class called Entity, mapped to table ENTITY with a mapping file called Entity.hbm.xml.

Is it possible to create a new instance of Entity using new Entity() and then have Hibernate fill this instance with data?
Something like:


Thanks!
Kjeld


 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kjeld:

What you'd need to do is:

1) Start a transaction
2) Create a new instance of Entity
3) Do all of your set methods
4) Commit the transaction
5) Have the session save the instance of Entity

John.
 
Kjeld Sigtermans
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John thanks for your reply, that might be the solution I was looking for.
First, let me clarify my original question. What I'd like to achieve to have Entity do some logic on another object.

So I'd like to use Entity as follows:


Thanks!
Kjeld

 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kjeld:

If you want to do that, you'll need to map Foo (or an implementation) to a table, and set a relationship (e.g., one-to-many). I'm not sure if you can directly map an interface or not, though.

John.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic