Persisting 3rd party objects with JPA

后端 未结 3 950
别跟我提以往
别跟我提以往 2020-12-16 06:08

In my current project I am using a 3rd party library which has no JPA annotations.

How can I persist objects from that library using JPA and external mappings?

3条回答
  •  我在风中等你
    2020-12-16 06:34

    Check this and this. In short:

    1. Create META-INF/orm.xml
    2. Follow (read) the .xsd

    You don't have to manually map each column - only some specifics (i.e. collections and the id) are required. All fields are assumed to be columns (if the class is mapped). If there are no collections, something like this suffices:

    
    
    
        External entities from library X
        com.external.library
        
          ..
        
        
          ..
        
    
    

    Note that when specifying you don't need fully-qualified names.

    In case you want a file named differently than orm.xml, in your persistence.xml specify it via:

    customMappingFile.xml
    

提交回复
热议问题