Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.hibernate.annotations.Type annotation does not work #166

Closed
jackmatt2 opened this issue Sep 13, 2017 · 4 comments
Closed

org.hibernate.annotations.Type annotation does not work #166

jackmatt2 opened this issue Sep 13, 2017 · 4 comments

Comments

@jackmatt2
Copy link

jackmatt2 commented Sep 13, 2017

Example type override

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Type(type="org.hibernate.type.PostgresUUIDType")
    private UUID id;

Exception when running generateChangeLog

SEVERE 13/09/17 4:31 PM: liquibase: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
liquibase.exception.DatabaseException: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
        at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:127)
        at liquibase.integration.commandline.Main.doMigration(Main.java:958)
        at liquibase.integration.commandline.Main.run(Main.java:188)
        at liquibase.integration.commandline.Main.main(Main.java:103)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:882)
        at liquibase.ext.hibernate.database.HibernateSpringPackageDatabase.createEntityManagerFactory(HibernateSpringPackageDatabase.java:94)
        at liquibase.ext.hibernate.database.HibernateEjb3Database.buildMetadataFromPath(HibernateEjb3Database.java:51)
        at liquibase.ext.hibernate.database.HibernateDatabase.buildMetadata(HibernateDatabase.java:136)
        at liquibase.ext.hibernate.database.HibernateDatabase.setConnection(HibernateDatabase.java:75)
        at liquibase.database.DatabaseFactory.findCorrectDatabaseImplementation(DatabaseFactory.java:131)
        at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:151)
        at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:85)
        ... 3 more
Caused by: org.hibernate.MappingException: Could not determine type for: pg-uuid, at table: email_address_aud, for columns: [org.hibernate.mapping.Column(id)]
        at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:431)
        at org.hibernate.tuple.PropertyFactory.buildStandardProperty(PropertyFactory.java:267)
        at org.hibernate.tuple.component.ComponentMetamodel.<init>(ComponentMetamodel.java:54)
        at org.hibernate.mapping.Component.getType(Component.java:169)
        at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:398)
        at org.hibernate.mapping.RootClass.validate(RootClass.java:266)
        at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:329)
        at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:443)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
        ... 10 more

┆Issue is synchronized with this Jira Bug by Unito

@crtk
Copy link

crtk commented Sep 13, 2017

try adding @Column with a columnDefinition (you may have to provide a matching @TypeDefs on a class somewhere in the path, iirc the package-info.java file does not work for liquibase -> #86 )

@jackmatt2
Copy link
Author

I tried adding

@TypeDefs({@TypeDef(name = "uuid", defaultForType = UUID.class, typeClass = PostgresUUIDType.class) })

on an actual @entity, but it still didn't work.

So adding a column like so

@Column(columnDefinition = "uuid", updatable = false)

Now generates a CHAR(36) column which is no good.

I was able to define a property like so

<property name="uuid" value="uuid" dbms="postgresql"/>

And do a find and replace for CHAR(36) to ${uuid}. This is a bit manual though.
.

@crtk
Copy link

crtk commented Sep 14, 2017

oh hmm.. PostgresUUIDType itself uses the name pg-uuid, might be worth trying

@filipelautert
Copy link
Collaborator

Liquibase core generates a char(36) when it doesn't recognizes the datbaase being used. For Postgresql it should generate the UUID type as per https://github.com/liquibase/liquibase/blob/bb97c1a27c4fe679609f7a3c72f662667c0f39c7/liquibase-standard/src/main/java/liquibase/datatype/core/UUIDType.java#L19 if you're using Postgresql 8.3+ .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants