JPA independent custom type mapping / javax persistence. X replaces org hibernate. annotations. Type and org hibernate. annotations. TypeDef

I have a table gamecycle in a database, which contains a column date of type number The value in this column is 8 digits, indicating the reciprocal date of "20130301" Mapped to this table, I have a gamecycle class that contains Java util. Protected field idate of type date This field is annotated with "@ type (type =" reversedate ")" using custom type mapping. Class gamecycle is annotated with "@ typedef (name =" reversedate ", typeclass = reversedatetype. Class)"

import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;

@Entity
@TypeDef(name = "inverseDate",typeClass = InverseDateType.class)
@Table(name = "GAMECYCLE")
public class GameCycle implements Comparable<GameCycle>,Serializable
{
    @Type(type = "inverseDate")
    @Column(name = "GC_DATE",nullable = false)
    protected Date iDate = null;
    ...

Obviously, I use hibernate as a JPA implementation for import binding, so my question is:

Is there any way to get rid of Hibernate annotations and use pure javax Does the persistence solution perform the same custom type mapping?

Solution

No, the current version of JPA specification does not support custom type mapping It is one of the most popular features of JPA 2.1 in the future

If you really want to get rid of Hibernate specific troubles, the only thing you can do is map your fields to strings and manually perform the necessary transformations (in getters / setters)

But in practice, almost every large application based on JPA uses some of the persistence provider to implement specific functions, so I don't think it's very important to avoid relying on Hibernate in this case

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>