orm - In Grails / Hibernate Can you set the generator to increment only if not assigned? -


Is there a way to use hibernated auto generated AIDS if it was not assigned, but if specified Uses the value?

I believe there is no box solution in Grails for this but it would be quite simple Should implement your own org.hibernate.id.IdentifierGenerator.

Implement the interface unless an ID is specified and otherwise your domain uses the value already assigned to the object. / P>

No charge is charged when assigned to a simple implementation identifier, when no key is assigned, it will look like this:

  package my.company.hibernate Import org.hibernate.engine.SessionImplementor Public Class PreAssignedIdGenerator extension of Org.hibernate.id.IdentityGenerator {Public Serializable Generation (session supplementary session, commodity object) {return object.id? Object.id: Super Generated (session, object)}}  

Your domain class will need to define the new ID generator:

  class FooDomain {Long ID Static Mapping = {ID Generator: "my.company.hibernate.PreAssignedIdGenerator"}}  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -