-->
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: @Any overriding in XML or Ejb3Configuration object
PostPosted: Fri Aug 06, 2010 3:03 am 
Newbie

Joined: Tue Jun 16, 2009 8:46 am
Posts: 1
Hi, I am developing a utility (something that will be packaged in a JAR to be used by third-party applications). That utility defines entities for item recommendations and tagging, without knowing exactly what entity is being recommended or tagged.

So we have something like this:

Code:
@Entity
public class Tag {
    @Id
    @GeneratedValue
    private Long id;

    private String tagName;

    @OneToMany
    private Collection<TagAssignment> assignments;

    // Other parts of the class omitted.
}

Code:
@Entity
public class TagAssignment {
    @Id
    @GeneratedValue
    private Long id;

    @AnyMetaDef(???)
    @Any(metaColumn=@Column(name="target_entity"), fetch=FetchType.EAGER)
    private Object target;

    @ManyToOne
    private Tag tag;

    // Other parts of the class omitted.
}


The problem is the @AnyMetaDef annotation. We don't know how to fill it because we don't know what type of entities the end user will have. It is a requeriment that we should be able to map that even if the target entities have different primary key types, including composite ones. A further requeriment is that the end user does not to know Java, so an approach where the XML files are used is preferred (it could be even better if we could completely avoid the XMLs too). If possible, generating some sort of meta information at runtime before the EntityManagerFactory is created is the best for us, as we already are creating an Ejb3Configuration object at runtime during the initialization and configuring properties and registering the entities at runtime on that object, so that would be the finest place to define the Any mapping data.

So, what sort of approach should I try to solve this problem? Is it possible to define the Any metadata using the Ejb3Configuration? If yes, how? If not, how do define them in XMLs? Is it possible to be modelled even if the entities' primary key types are different?

Actually, we are handling that with an embedded class called GenericReference which persist the target entity class name and a serialized version of it's Id. However, we must do this by hand and we are getting some issues, but this is something that Hibernate for sure could/should automate, as this is the purpose of the @Any annotation.


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.