Friday, June 4, 2010

@XmlTransient and @Transient

@Transient is a JPA annotation which specified that the field is not going to be persistent. But @XmlTransient one of JAXB annotations is to exclude the field when marshalling the Java objects to a xml file.

I ever made a stupid mistake and replaced @Transient with an @XmlTransient, and thought @XmlTransient would do both things. How could I come up with such "thought"?

Obviously, that would throw up tons of unit test failures with the following exceptions:
Caused by: org.hibernate.PropertyAccessException: could not set a field value by reflection setter of uk.co.ondemand.cmm.service.persistence.Product.providerAssetId
......
Caused by: java.lang.IllegalArgumentException
......
The reason of those exceptions is that the unit tests started persisting the field but couldn't find any corresponding values in the test data, say DBUnit. That meant it couldn't insert a value into a field hasn't been defined in the test data.

No comments: