hibernate.id.new_generator_mappings

843 views
Skip to first unread message

Jerry Thome

unread,
Jul 17, 2019, 8:57:57 AM7/17/19
to Quarkus Development mailing list
Is there a way to set "hibernate.id.new_generator_mappings" to be false outside of creating the persistence.xml?

<property name="hibernate.id.new_generator_mappings" value="false"/>

Needless to say, I spent hours trying to get 'sequence' to work correctly between Hibernate and SQL Server.  I kept seeing reference to setting this property to false.  The only way I got it to work was by creating persistence.xml and adding it there.  As you all know, once you do that, you have to move all of the quarkus.hibernate-orm.* properties and it's not always an easy migration.  For portability and speed, I'd like to keep using H2 for unit testing.  So now, I have significant differences between 'test' and 'dev' which is easily managed in the application.properties, but more challenging if I have to make variable in the persistence.xml.

So, I think my options are 1) somehow set "hibernate.id.new_generator_mappings" outside of persistence.xml, or 2) parameterize basically everything that I'd put in persistence.xml.

I am running this as a Maven project.

Thoughts?

Thanks.

Jerry Thome

unread,
Jul 17, 2019, 12:36:24 PM7/17/19
to Quarkus Development mailing list
Ultimately, I'm trying to manage the database via flyway and use Quarkus and ORM at runtime.  I'm trying to define a Table and corresponding ID attribute properly so that I can use Identity or Sequence.  I've tried various combinations of 

@GeneratedValue(strategy = GenerationType.XXX) 

with 

id int IDENTITY(1,1), 
or 
[id] [bigint] PRIMARY KEY NOT NULL DEFAULT (NEXT VALUE FOR dbo.CustomerID), 

and it keeps coming back to SQL Error: 208, SQLState: S0002 / Invalid object name 'hibernate_sequence' when I try to persist a new entity, until I set "hibernate.id.new_generator_mappings" to "false".

Moving configuration to persistence.xml seems to have a ton of downside.  For example, I'll have to move quarkus.hibernate-orm.database.generation=drop-and-create to persistence.xml and I'll lose the ability to toggle by environment.

I'm hoping someone has an example how to properly define a table's ID and the corresponding annotations that might be needed in the Entity without having to set "hibernate.id.new_generator_mappings" to false.

Right now I have working....

CREATE SEQUENCE CustomerID
    START WITH 1
    INCREMENT BY 1
    NO CACHE
    ;    
    
CREATE TABLE [Customer](
    [id] [bigint] PRIMARY KEY NOT NULL DEFAULT (NEXT VALUE FOR dbo.CustomerID),
    [name] [varchar](255) NOT NULL);

extending PanacheEntity and using the default...
@Id
@GeneratedValue
public Long id;
    
and setting "hibernate.id.new_generator_mappings" to "false" in the persistence.xml.  As mentioned above, this begins to limit flexibility.

Thanks for any help on this frustrating scenario.

Guillaume Smet

unread,
Jul 17, 2019, 12:53:19 PM7/17/19
to jerry...@gmail.com, Quarkus Development mailing list
Have you tried not extending PanacheEntity (use PanacheEntityBase instead) and have this on your id:
@GeneratedValue(strategy = GenerationType.IDENTITY)
?

If you use that, I don't see how you could end up with an invalid hibernate_sequence object.

--
Guillaume

--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.
Visit this group at https://groups.google.com/group/quarkus-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/7b8282d4-433d-49d5-951f-9ff62b2d6cfd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jerry Thome

unread,
Jul 17, 2019, 8:43:49 PM7/17/19
to Quarkus Development mailing list
Great idea.  I ended up not extending anything for my Entity.  I'm using a Repository that implements 'PanacheRepository' that provides the easy access APIs for persisting my Entity.  So far, works great.

Thank you for the suggestion.


Reply all
Reply to author
Forward
0 new messages