Assign custom identifier to an @id property

后端 未结 2 1481
一个人的身影
一个人的身影 2020-12-30 11:11

I\'m migrating a legacy system over to use Hibernate 3. It currently generates its own identifiers. To keep with what the system currently does before I try and move it ov

2条回答
  •  忘掉有多难
    2020-12-30 11:32

    You can.

    First, implement org.hibernate.id.IdentifierGenerator

    Then you'd have to map it in a mapping xml file. I couldn't find a way to do this with annotations:

    
    
        
        
    

    Finally, use @GeneratedValue(generator="identifier-name")

    Note that this is hibernate-specific (not JPA)

    Update: I took a look at the sources of Hibernate, and it seems at one place, after failing to resolve the short name, hibernates attempts to call Class.forName(..). The parameter there is called strategy. So Here's what you try:

    • try setting the class fully-qualified name as string in the generator attribute
    • try setting the class fqn as string in the @GenericGenerator strategy attribute (with some arbitrary name)

    Let me know which (if any) worked

提交回复
热议问题