views:

46

answers:

2

The question is in the title.

Some explanation: I can't implement necessary mapping. But I can get all necessary data using queries in DAOs. So, I want to insert that data manually to my entity in DAOs findAll () method.

But JPA treats all entity's fields as persistent attributes and adds them to generated sql-queries. Of course, I get an exception that query cannot be performed. So, I need to state that 'this field will be set manually, skip it'.

P.S. This solution sounds ugly even to me, but I cant find any better solution because I have 'immutable' DB schema and I need to map it on my entities.

+3  A: 

Use the @Transient annotation

FRotthowe
+1  A: 

This is off the top of my head and could be wrong, but...

isn't there an @transient annotation? Or simply the transient Java modifier?

I think JPA won't mess with fields thus marked.

Carl Smotricz
+1 for mentioning the `transient` keyword, which is certainly honoured by Hibernate and I believe by JPA. It makes a lot of sense to use the lower-level language features when they're truly appropriate, rather than annotations.
Andrzej Doyle