Using DTOs as Entities [message #1439546] |
Tue, 07 October 2014 09:05 |
Dan Hargreaves Messages: 7 Registered: November 2010 |
Junior Member |
|
|
Hi,
I've worked with JPA before and we had a DTO layer and a JPA entity layer. Both of these were separate from our actual data model meaning that we had to map between data model <-> DTO <-> JPA entity.
What I would like to do this time around is use the DTO as the basis of the persistence. We don't have any real need for performance in the database layer so the plan would be to generate the schema from the JPA entities/DTOs.
The thing is, to ensure we only send the data we need through RMI, where one entity references another this is reduced to its ID. What I would like to do is use an annotation or something to be able to convert this ID back into its object equivalent and then persist it with a foreign key reference.
So
@Entity
public class MyDTO implements Serializable
{
@ID
public long id;
public String aField;
//Reference to a 'OtherDTO' instance
public long otherDTO;
}
So I have tried a few different combinations of annotations but I can't seem to generate the database as I would like.
Is there a combination of annotations that would let me do this, or an annotation that changes the type of the field to say 'OtherDTO' and allows me to specify a converter so that the schema is generated with a foreign key to the OtherDTO table.
Many thanks for any help!
[Updated on: Tue, 07 October 2014 12:57] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02074 seconds