Hi all.
I'm still juggeling with my EclipseLink test-project,
https://github.com/andreak/hibernatetest, (on my quest for migrating away from Hibernate) and now I'm stuck with @Converter not being picked up. I'm having a Spring-wired environment (no persistence.xml etc.) and my @Converter class for converting joda-time's DateTime is not being picked up.
My converter looks like this:
@Converter(autoApply = true)
public class JodaDateTimeConverter implements AttributeConverter<DateTime, Timestamp> {
@Override
public Timestamp convertToDatabaseColumn(DateTime attribute) {
if (attribute == null) {
return null;
} else {
return new Timestamp(attribute.getMillis());
}
}
@Override
public DateTime convertToEntityAttribute(Timestamp dbData) {
if (dbData == null) {
return null;
} else {
return new DateTime(dbData.getTime());
}
}
}
Using DERBY as embedded DB, EclipseLink generates the following SQL:
[EL Fine]: sql: 2013-07-04 14:11:24.603--ServerSession(555941420)--Connection(1076476202)--Thread(Thread[main,5,main])--CREATE TABLE car (id BIGINT NOT NULL, created BLOB(2147483647) NOT NULL, model VARCHAR(255) NOT NULL, owner_name VARCHAR(255), data_id BIGINT, PRIMARY KEY (id))
Where "created" is of type org.joda.time.DateTime. As you can see EL creates a BLOB for that column, not Timestamp
In my real project I have a persistence-unit spread over lots of modules (maven) and have used Spring's "packagesToScan"-attribute of LocalContainerEntityManagerFactoryBean to locate all my entities and building up the PU, thus eliminating the need for maintaining persistence.xml/orm.xml.
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="packagesToScan" value="no.officenet.test"/>
<property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
<property name="jpaDialect" ref="jpaDialect"/>
<property name="jpaProperties">
<props>
<prop key="eclipselink.cache.shared.default">false</prop>
<prop key="javax.persistence.sharedCache.mode">ENABLE_SELECTIVE</prop>
</props>
</property>
</bean>
I'd rather not have to maintain persistence.xml/orm.xml as it becomes a maintainence-nightmare when having lots modules.
I have also tried this with PostgreSQL as DB creating the column manually and then EL complains with:
org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error converting parameter 0
Error Code: 0
Call: INSERT INTO car (created, model, owner_name, data_id, id) VALUES (?, ?, ?, ?, ?)
bind => [[B@5c787c2d, Vamonda!, null, 36, 211]
Query: InsertObjectQuery(no.officenet.test.hibernatetest.model.Car@5eb9ec47)
Any help is most welcome, thanks.
--
Andreas Joseph Krogh <andreak@xxxxxxxxxxxx> mob: +47 909 56 963
Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no
Public key: http://home.officenet.no/~andreak/public_key.asc