[hibernate-issues] [Hibernate-JIRA] Commented: (ANN-698) Unbound property when default field access is used lead to unbound AnnotationException

Jesse Sweetland (JIRA) noreply at atlassian.com
Mon Jun 1 09:33:13 EDT 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/ANN-698?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=33295#action_33295 ] 

Jesse Sweetland commented on ANN-698:
-------------------------------------

I've run into the same issue and I think the problem has more to do with the fact that the initial mapping validation logic looks at both fields and properties before deciding whether field annotations or property annotations are being used.  In my case I have this:

@Entity
public class Foo<B extends Bar> implements Serializable {
    private static final long serialVersionUID = 1L;

    // ...

    @ManyToOne
    private Bar bar;

    // ...

    public B getBar() {
        return (B)bar;
    }

    public void setBar(B bar) {
        this.bar = bar;
    }
}

In this case I'm using field annotations and mapping to a concrete entity type (Bar) but using a properties to enforce strong typing. I can make Hibernate happy by putting @Transient annotations on the accessor and mutator methods.  Netbeans throws a fit, but it compiles and deploys just fine.



> Unbound property when default field access is used lead to unbound AnnotationException
> --------------------------------------------------------------------------------------
>
>                 Key: ANN-698
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-698
>             Project: Hibernate Annotations
>          Issue Type: Bug
>    Affects Versions: 3.3.0.ga
>         Environment: hibernate3.jar: 3.2.5.ga
> hibernate-annotations.jar: 3.3.0.GA
> hibernate-commons-annotations.jar: 3.0.0.GA
> hibernate-validator.jar: 3.0.0.GA
> MySQL
>            Reporter: Sebastian Baltes
>             Fix For: 3.3.1.CR1
>
>         Attachments: log.txt
>
>
> Transient fields are not ignored in Hibernate. I got an "Property has an unbound type" exception and found no workaround.
> Entity:
> import javax.persistence.Entity;
> import javax.persistence.Id;
> import javax.persistence.Transient;
> @Entity
> public class Dummy<K> {
>   
>   @Id
>   private Long id;
>   
>   @Transient
>   transient private K dummyField;
>   public Long getId() {
>     return id;
>   }
>   public void setId(Long id) {
>     this.id = id;
>   }
>   public K getDummyField() {
>     return dummyField;
>   }
>   public void setDummyField(K dummyField) {
>     this.dummyField = dummyField;
>   }
> }
> Test Code:
>       EntityManager em = EntityManagerSingleton.get();
>       EntityTransaction tx = em.getTransaction();
>       tx.begin();
>       Dummy a = new Dummy();
>       em.persist(a);
>       tx.commit();
> Exception:
> java.lang.ExceptionInInitializerError
> 	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
> 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
> 	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
> 	at junit.framework.TestSuite.createTest(TestSuite.java:54)
> 	at junit.framework.TestSuite.addTestMethod(TestSuite.java:280)
> 	at junit.framework.TestSuite.<init>(TestSuite.java:140)
> 	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.getTest(JUnit3TestLoader.java:102)
> 	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.loadTests(JUnit3TestLoader.java:59)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:445)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
> Caused by: javax.persistence.PersistenceException: org.hibernate.AnnotationException: Property de.neise.gena.model.file.Dummy.dummyField has an unbound type and no explicit target entity. Resolve this Generic usage issue or set an explicit target attribute (eg @OneToMany(target=) or use an explicit @Type
> 	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:258)
> 	at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
> 	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
> 	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
> 	at de.neise.gena.model.testbase.BaseTest.<clinit>(BaseTest.java:19)
> 	... 13 more
> Caused by: org.hibernate.AnnotationException: Property de.neise.gena.model.file.Dummy.dummyField has an unbound type and no explicit target entity. Resolve this Generic usage issue or set an explicit target attribute (eg @OneToMany(target=) or use an explicit @Type
> 	at org.hibernate.cfg.AnnotationBinder.addElementsOfAClass(AnnotationBinder.java:993)
> 	at org.hibernate.cfg.AnnotationBinder.getElementsToProcess(AnnotationBinder.java:833)
> 	at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:645)
> 	at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:498)
> 	at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:277)
> 	at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
> 	at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1269)
> 	at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:150)
> 	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:888)
> 	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:186)
> 	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:246)
> 	... 17 more

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list