0

I'm using JPA with Hibernate. For the entities defined in my app, I use annotations, but some of the entities come as third-party code without any mappings. Therefore I have to map them via XML (at least I think I have to):

<entity-mappings ...>
    <access>FIELD</access>

    <mapped-superclass class="com.acme.common.model.Request">
        <attributes>
            <id name="id"/>
        </attributes>
    </mapped-superclass>
</entity-mappings>

Since this is JPA mapping, it works great except for one case where I have to use a Hibernate specific custom type to map PostgreSQL's uuid type to java.util.UUID.

Using annotations, it's a piece of cake:

@Entity
public class Partner {
    @Id
    @Type(type = "org.hibernate.type.PostgresUUIDType")
    private UUID id = IdGenerator.generate();
}

The problem is that I can't figure out how to do the same via XML.

I considered using Hibernate's native XML mapping, but it seems like it doesn't support mapped superclasses.

2

1 Answer 1

1

JPA mappings only supports its native API. You would need to use the hbm file.

You will have to migrate to a hbm mapping file with the property like:

Check out here for more details: http://docs.jboss.org/hibernate/orm/3.6/quickstart/en-US/html/hibernate-gsg-tutorial-basic.html

Sign up to request clarification or add additional context in comments.

2 Comments

Does it mean I can't get the best of both worlds with XML like with annotations? I mean, I can combine both JPA and Hibernate annotations. By switching to Hibernate XML, does it mean I'll have to give up JPA features like mapped super classes?
You can have the JPA features, but you would need to use only Hibernate mappings. I never heard about a feature that allow a hbm file to import a orm (jpa only) file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.