-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to define hibernate mapping for a domain library
PostPosted: Wed Jul 02, 2014 6:44 pm 
Newbie

Joined: Wed Jul 02, 2014 6:42 pm
Posts: 1
I have implemented a modular domain/model library, this is shared among other projects. I would like to define hibernate mapping for domain classes at the library and be able to extend it from the referencing projects, in order to keep information used in one project within itself only. I think the best way to do this would be to define annotated interfaces (with @MappedSuperclass) in the library and implement those in the concrete classes at the referencing project:
Code:
//at the domain library
@MappedSuperclass
public interface MyInterface{
    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
}

//at the extending project
@Entity
public class MyClass implements MyInterface{   
    @Column(name="extension")   
    private String extension;
}

Unfortunately annotated interfaces still not supported by JPA. This is possible if I use abstract classes instead of interfaces, but this would limitate the model architecture of the projects referencing the library, since java does not support multiple inheritance. Another way I tought of is to put the mapping into hibernate.cfg.xml files, this proprietary configuration allows to do something like:
Code:
<class name="model.MyInterface" table="mytable">

    <id name="id" type="int" column="id">
        <generator class="native"/>
    </id>

    <subclass name="model.impl.MyClass" discriminator-value="IMPL" >
        ... properties / extensions ...
    </subclass>

</class>

In this case this configuration would be placed at the library and referenced from the extending project persistence.xml. Then, the extensions would be defined in xml files placed also at the exending project and included into the configuration file at the library.

Is it possible to inlcude the xml files this way ? I tryed using XML ENTITY, but the parser complains that the content is not expected at the line of the include, no matter what the included file contains.

What would be the best way to define extensible database mapping for a modular domain library? Should I use JDO instead (would like to avoid) ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.