-->
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.  [ 2 posts ] 
Author Message
 Post subject: JPA SingularAttribute.isAssociation is always FALSE
PostPosted: Tue May 03, 2011 3:10 am 
Newbie

Joined: Thu Nov 03, 2005 11:21 am
Posts: 2
Hibernate implementation of the javax.persistence.metamodel.SingularAttribute interface (org.hibernate.ejb.metamodel.SingularAttributeImpl) always return false in the isAssociation method (hibernate 3.6.1).

So the JPA metamodel is unusable in some cases. Eg.:

Standard parent-child relation:
Code:
@Entity
public class ChildEntity {
    private Long id;
    private String name;
    private ParentEntity parent;

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column( name = "ID" )
    public ID getId() { return this.id; }

    public void setId( ID id ) { this.id = id; }

    @Column( name = "NAME", nullable = false, length = 50 )
    public String getName() { return this.name; }

    public void setName( String name ) { this.name = name; }

    @ManyToOne
    @JoinColumn( name = "PARENT_ID", nullable = false )
    public ParentEntity getParent() { return this.parent; }

    public void setParent( ParentEntity parent ) { this.parent = parent; }

}

@Entity
public class ParentEntity {
    private Long id;
    private String name;
    private Set<ChildEntity> childs = new HashSet<ChildEntity>();

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column( name = "ID" )
    public ID getId() { return this.id; }

    public void setId( ID id ) { this.id = id; }

    @Column( name = "NAME", nullable = false, length = 50 )
    public String getName() { return this.name; }

    public void setName( String name ) { this.name = name; }

    @OneToMany( mappedBy = "parent", cascade = { CascadeType.ALL } )
    public Set<ChildEntity> getChilds() { return this.childs; }

    public void setChilds( Set<ChildEntity> childs ) { this.childs = childs; }

}


Testing the parent-child relation through the metamodel:
Code:
...

EntityManager entityManager = this.entityManagerFactory.createEntityManager();

ManagedType< ? > managedTypePE = entityManager.getMetamodel().entity( ParentEntity.class );
Attribute<?, ?> attrPEChilds = managedTypePE.getAttribute( "childs" );
Assert.assertTrue( attrPEChilds.isCollection() ); // its OK

ManagedType< ? > managedTypeCE = entityManager.getMetamodel().entity( ChildEntity.class );
Attribute<?, ?> attrCEParent = managedTypeCE.getAttribute( "parent" ); // <<== it will be a SingularAttribute
Assert.assertTrue( attrCEParent.isAssociation() ); // <<== THIS WILL FAIL!!!

...


Top
 Profile  
 
 Post subject: Re: JPA SingularAttribute.isAssociation is always FALSE
PostPosted: Mon Nov 19, 2012 5:56 am 
Newbie

Joined: Tue Jul 08, 2008 8:02 am
Posts: 10
Is there a bug for this? I think it is a bug.


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

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.