Serialization with @Transient fields
Hello everybody, I have created an entity having attributes which should be persisted and attriutes which should not be persisted marked with the @Transient annotation. For example it is something like this: @Entity public class MyEntity implements Serializable { @Column protected int myInteger; @Transient protected List myList; // And so on } I need the transient field for holding some content during the application which needs not to be persisted. Now I want to serialize MyEntity, but there is the problem: All fields marked with @Transient are not serialized. I know there is the "transient" modifier which excludes attributes from serialization, but has @Transient the same effect? How can I make the application serializing @Transient fields without having to persist them? Has anyone an idea? Greetings! Naomi
Re: Inheritance: Subclasses are not recognised
Hello everybody, after spending half of my weekend, I got it to work. I do not know exactly WHY it works that way, but I think this is marginal ;) If someone can explain it to me, feel free to do so, I would be glad. It seems that the cause was a combination of bad Spring configuration and some anomalies in my project. So lets have a look on how I solved the problem: First, I wanted to try to persist one of the subclasses, because I wanted to see what discriminator value would be written to the database. Because I only need to read that subclass from other objects and do not need to call them directly from database, I created a new Spring DAO for this persist task. I found out, that persisting did not work either and thus realised that I did not include a transaction manager (it was configured, but not linked - too bad :\ ). After reconfiguring the Spring framework I was able to persist the entity without any problems. After that, I ran my application again and - it suddenly recognised the entity persisted before (but still not the other subclasses). After some try-and-error, I found out: To make Spring / OpenJPA recognise the discriminator values, the subclasses have to be a) directly related to any entity, that can be called with a Spring DAO or b) directly called with a Spring DAO If only the superclass is related / called, the discriminator value of the subclasses will not be recognised. Maybe some OpenJPA / Spring experts will laugh at me, but please explain me, why it works that way ^^" Original-Nachricht > Datum: Fri, 15 May 2009 16:47:31 +0200 > Von: "Jasmin Riemer" > An: users@openjpa.apache.org > Betreff: Re: Inheritance: Subclasses are not recognised > Hi Mike, > > yes, I have. > This was also my first thought about that problem ;) > Maybe other configurations in persistence.xml that may cause problems? > > >value="root"/> > >value="jdbc:mysql://localhost:3306/ghostbase"/> >value="com.mysql.jdbc.Driver"/> >value="mysql(TableType=myisam)"/> > > > > -Jasmin > > Original-Nachricht > > Datum: Fri, 15 May 2009 09:25:54 -0500 > > Von: Michael Dick > > An: users@openjpa.apache.org > > Betreff: Re: Inheritance: Subclasses are not recognised > > > Hi Jasmin, > > > > Do you have all your entities listed in persistence.xml? > > > > -mike > > > > On Fri, May 15, 2009 at 7:08 AM, Jasmin Riemer > > wrote: > > > > > Hello everybody, > > > > > > currently, I am working with OpenJPA in the Spring framework and try > to > > > implement the following: > > > > > > I inherit certain subclasses from a mainclass. All these classes > should > > be > > > mapped to a single table, so I use InheritanceType.SINGLE_TABLE and > add > > a > > > discriminator value to each subclass. > > > > > > Simplified, it looks like this: > > > > > > @Entity > > > @Inheritance(strategy=InheritanceType.SINGLE_TABLE) > > > @DiscriminatorColumn(name="doc_type", > > > discriminatorType=DiscriminatorType.STRING) > > > public abstract class Document { > > > > > > // ... > > > > > > } > > > > > > @Entity > > > @DiscriminatorValue(value="Magazine") > > > public class Magazine extends Document { > > > > > > // ... > > > > > > } > > > > > > @Entity > > > @DiscriminatorValue(value="Book") > > > public class Book extends Document { > > > > > > // ... > > > > > > } > > > > > > Unfortunately, I get the following error message when I try to load > data > > > from the database: > > > > > > Exception in thread "main" > > > org.springframework.dao.InvalidDataAccessApiUsageE xception: Could not > > map > > > discriminator value "Book" to any known subclasses of the requested > > class > > > "project.entities.Document" (known discriminator values: [Document, > > > Magazine]).; nested exception is nonfatal > > user > > > error> org.apache.openjpa.persistence.ArgumentException: Could not map > > > discriminator value "Book" to any known subclasses of the requested > > class > > > "project.entities.Document" (known discriminator values: [Document, > >
Re: Inheritance: Subclasses are not recognised
Hi Mike, yes, I have. This was also my first thought about that problem ;) Maybe other configurations in persistence.xml that may cause problems? -Jasmin Original-Nachricht > Datum: Fri, 15 May 2009 09:25:54 -0500 > Von: Michael Dick > An: users@openjpa.apache.org > Betreff: Re: Inheritance: Subclasses are not recognised > Hi Jasmin, > > Do you have all your entities listed in persistence.xml? > > -mike > > On Fri, May 15, 2009 at 7:08 AM, Jasmin Riemer > wrote: > > > Hello everybody, > > > > currently, I am working with OpenJPA in the Spring framework and try to > > implement the following: > > > > I inherit certain subclasses from a mainclass. All these classes should > be > > mapped to a single table, so I use InheritanceType.SINGLE_TABLE and add > a > > discriminator value to each subclass. > > > > Simplified, it looks like this: > > > > @Entity > > @Inheritance(strategy=InheritanceType.SINGLE_TABLE) > > @DiscriminatorColumn(name="doc_type", > > discriminatorType=DiscriminatorType.STRING) > > public abstract class Document { > > > > // ... > > > > } > > > > @Entity > > @DiscriminatorValue(value="Magazine") > > public class Magazine extends Document { > > > > // ... > > > > } > > > > @Entity > > @DiscriminatorValue(value="Book") > > public class Book extends Document { > > > > // ... > > > > } > > > > Unfortunately, I get the following error message when I try to load data > > from the database: > > > > Exception in thread "main" > > org.springframework.dao.InvalidDataAccessApiUsageE xception: Could not > map > > discriminator value "Book" to any known subclasses of the requested > class > > "project.entities.Document" (known discriminator values: [Document, > > Magazine]).; nested exception is user > > error> org.apache.openjpa.persistence.ArgumentException: Could not map > > discriminator value "Book" to any known subclasses of the requested > class > > "project.entities.Document" (known discriminator values: [Document, > > Magazine]). > > > > It seems that there are only known the main class and the subclass > > "Magazine", but there is a problem with "Book" (and some other classes > > inherited from "Document"). > > > > I do not have much experience with OpenJPA and Spring and thus I have no > > clue how to solve this problem. Anybody out there who has an idea or > maybe > > had a similar problem? > > Is there maybe something special I could have used accidentally for > > "Magazine", but not for the other classes? > > -- > > Neu: GMX FreeDSL Komplettanschluss mit DSL 6.000 Flatrate + > > Telefonanschluss für nur 17,95 Euro/mtl.!* > > http://dslspecial.gmx.de/freedsl-surfflat/?ac=OM.AD.PD003K11308T4569a > > -- Neu: GMX FreeDSL Komplettanschluss mit DSL 6.000 Flatrate + Telefonanschluss für nur 17,95 Euro/mtl.!* http://dslspecial.gmx.de/freedsl-surfflat/?ac=OM.AD.PD003K11308T4569a
Inheritance: Subclasses are not recognised
Hello everybody, currently, I am working with OpenJPA in the Spring framework and try to implement the following: I inherit certain subclasses from a mainclass. All these classes should be mapped to a single table, so I use InheritanceType.SINGLE_TABLE and add a discriminator value to each subclass. Simplified, it looks like this: @Entity @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name="doc_type", discriminatorType=DiscriminatorType.STRING) public abstract class Document { // ... } @Entity @DiscriminatorValue(value="Magazine") public class Magazine extends Document { // ... } @Entity @DiscriminatorValue(value="Book") public class Book extends Document { // ... } Unfortunately, I get the following error message when I try to load data from the database: Exception in thread "main" org.springframework.dao.InvalidDataAccessApiUsageE xception: Could not map discriminator value "Book" to any known subclasses of the requested class "project.entities.Document" (known discriminator values: [Document, Magazine]).; nested exception is org.apache.openjpa.persistence.ArgumentException: Could not map discriminator value "Book" to any known subclasses of the requested class "project.entities.Document" (known discriminator values: [Document, Magazine]). It seems that there are only known the main class and the subclass "Magazine", but there is a problem with "Book" (and some other classes inherited from "Document"). I do not have much experience with OpenJPA and Spring and thus I have no clue how to solve this problem. Anybody out there who has an idea or maybe had a similar problem? Is there maybe something special I could have used accidentally for "Magazine", but not for the other classes? -- Neu: GMX FreeDSL Komplettanschluss mit DSL 6.000 Flatrate + Telefonanschluss für nur 17,95 Euro/mtl.!* http://dslspecial.gmx.de/freedsl-surfflat/?ac=OM.AD.PD003K11308T4569a