liquibase-hibernate
liquibase-hibernate copied to clipboard
Hibernate Annotations package scan not works package-info
I work with spring-boot, and have no persistence.xml file, I configured a TypeDef in file package-info.java, I set hibernate.hmb2ddl.auto to create, run the test case, the type in the database will surely be datetime, but it doesn't work with liquibase-hibernate spring connection. here is my configuraion in the pom.xml.
<plugin>
<!-- ... -->
<configuration>
<url>jdbc:mariadb://localhost:3306/oj?zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8</url>
<username>root</username>
<password>root</password>
<!-- see liquibase.ext.hibernate.database.HibernateSpringDatabase -->
<!-- see org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager -->
<referenceUrl>hibernate:spring:com.github.zhanhb.judge.domain?dialect=org.hibernate.dialect.MySQLInnoDBDialect</referenceUrl>
<changeLogFile>${project.build.resources[0].directory}/config/liquibase/master.xml</changeLogFile>
<diffChangeLogFile>${project.build.resources[0].directory}/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml</diffChangeLogFile>
<logging>debug</logging>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<verbose>true</verbose>
<systemProperties>
<logback.configurationFile>${project.build.resources[0].directory}/logback.xml</logback.configurationFile>
</systemProperties>
</configuration>
</plugin>
here is the codes in my package-info.java
@TypeDefs({
@TypeDef(name = "localDateType", typeClass = org.jadira.usertype.dateandtime.threeten.PersistentLocalDate.class, defaultForType = java.time.LocalDate.class),
@TypeDef(name = "localDateTimeType", typeClass = org.jadira.usertype.dateandtime.threeten.PersistentLocalDateTime.class, defaultForType = java.time.LocalDateTime.class),
@TypeDef(name = "localTimeType", typeClass = org.jadira.usertype.dateandtime.threeten.PersistentLocalTime.class, defaultForType = java.time.LocalTime.class)
})
package com.github.zhanhb.judge.domain;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
<properties>
<asm.version>5.0.4</asm.version>
<javassist.version>3.20.0-GA</javassist.version>
<spring-boot.version>1.2.5.RELEASE</spring-boot.version>
<maven.version>3.3.3</maven.version>
<liquibase-hibernate4.version>3.5</liquibase-hibernate4.version>
<liquibase.version>3.4.0</liquibase.version>
<hibernate.version>4.3.10.Final</hibernate.version>
<usertype.version>4.0.0.GA</usertype.version>
</properties>
If I put @TypeDefs on to any entity class, it works ok, but can it works I put it on to package-info???
Any progress on that? I have similar issue with
@GenericGenerator(
name = DEFAULT_GENERATOR,
strategy = SEQUENCE_STYLE_GENERATOR,
parameters = @Parameter(name = SEQUENCE_PARAM, value = "default_sequence")
)
on the package level
+1
+1 - Does Hibernate scan for annotations on interfaces ? As a quick workaround can we use
@TypeDefs({
@TypeDef(name = "type1", typeClass = foo.bar.Type1),
@TypeDef(name = "type2", typeClass = foo.bar.Type2),
@TypeDef(name = "type3", typeClass = foo.bar.Type3)
})
public interface Marker {
// nothing
}
@Entity
public class MyEntity implements Marker {
private foo.bar.Type1 type1Value;
public MyEntity() {
super();
}
@Column
public foo.bar.Type1 getSpecialType1() {
return type1Value;
}
public void setSpecialType1(foo.bar.Type1 type1Value) {
this.type1Value = type1Value;
}
}
I have a similar problem but with the @FilterDef annotation at package level.
For exmaple with this wont work (package-info.java):
@FilterDef(name = "deletedFilter", defaultCondition = "deleted_at IS NULL")
package hu.webdream.iunox.model;
import org.hibernate.annotations.FilterDef;
When I run from maven the liquibase:diff command it fails with this error:
[ERROR] Error setting up or running Liquibase:
[ERROR] org.hibernate.AnnotationException: Entity 'Group' has a '@Filter' for an undefined filter named 'deletedFilter'
However it works fine in my Spring application.