tags:

views:

28

answers:

2

Hi All,

Considering Hibernate 3,

I would like to map a legacy class to a new Db table. (I have to use a legacy model .jar and have to store these objects in a new db) But my legacy object does not declare a default no arg constructor and i am not able to change the contract because it is part of an API model. (shared by legacy apps). I neither do not want to write a new class for this and do not want to transcode from one to other.

Let's say I have a class with 3 attributes and only a default constructor(arg0,arg1,arg2), and each arg has to be mapped with a column in db (table with 3 col). I have to store and retrieve objects.

Would it be possible without having to declare a default no arg constructor ? Using an interceptor ? would it be possible to access 3 columns to call constructor with args ?

NB : sorry, i forgot to say, no setter on these 3 attributes to ensure developpers use the 3 args constructor.

Thanks by advance.

+1  A: 

You could implement a Interceptor that calls the constructor.

See this forum post. There are probably better resources out there.

Stefan Steinegger
Hi, thanks for you answer. But i do not think that solution would let me map a few columns -three for me- to a three arg constructor. I do not understand how EmptyInterceptor instantiate signature will let me do this ?
tom_hawak
A: 

You could probably implement a tuplizer to solve this. Here is the API doc. Here is also some documentation about it.

Stefan Steinegger