-->
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.  [ 7 posts ] 
Author Message
 Post subject: targeting an unmapped class: [java.lang.Boolean]
PostPosted: Thu May 12, 2011 7:51 am 
Newbie

Joined: Wed Dec 29, 2010 8:58 am
Posts: 10
Hello, I don't understand this error, because Boolean is a java class, so I guess it is not necesarry to map. Anyway here I add my code:
TaskAssignationState
Code:
protected Map<User, Boolean> usersState;
@ManyToMany
   @JoinTable(name = "user_state_task_assignation",
          joinColumns=@JoinColumn(name="assignation_state"),
            inverseJoinColumns=@JoinColumn(name="username"))   
    @MapKeyJoinColumn(name="state")
    public Map<User, Boolean> getUsersState() {
        return usersState;
    }
    public void setUsersState(Map<User, Boolean> usersState) {
        this.usersState = usersState;
    }


User

Code:
@ManyToMany(
    cascade={CascadeType.ALL},   
    mappedBy = "userState",
    fetch=FetchType.LAZY
   )
   public List<TaskAssignationState> getTaskAssignationState() {
      return taskAssignationState;
   }

   public void setTaskAssignationState(List<TaskAssignationState> taskAssignationState) {
      this.taskAssignationState = taskAssignationState;
   }


Then, the exception:

Quote:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext-dao.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.path.TaskAssignationState.usersState[java.lang.Boolean]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1412)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:546)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
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 org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:202)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:251)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:248)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


I tryed to map the Boolean class on hibernate.cfg.xml, but no success. Why could it happen?? Thanks in advance


Top
 Profile  
 
 Post subject: Re: targeting an unmapped class: [java.lang.Boolean]
PostPosted: Thu May 12, 2011 9:23 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
You are using the wrong annotation. @ManyToMany is between entities. @ElementCollection seems what you are after, but that only works if User is an Embeddable. If User is an entity you cannot map it in JPA/Hibernate.


Top
 Profile  
 
 Post subject: Re: targeting an unmapped class: [java.lang.Boolean]
PostPosted: Thu May 12, 2011 11:01 am 
Newbie

Joined: Wed Dec 29, 2010 8:58 am
Posts: 10
But User is an entity which is referenced by any others in the model, would it make any problem to these relations?


Top
 Profile  
 
 Post subject: Re: targeting an unmapped class: [java.lang.Boolean]
PostPosted: Fri May 13, 2011 3:03 am 
Newbie

Joined: Wed Dec 29, 2010 8:58 am
Posts: 10
As you say User is an entity, so I can not map it in the way I want and I explained. So how could I make this mapping?? Could you tell me an alternative solution please??
I need somehow to have a structure like <User, Boolean>, to know if one User is active or not, just this flag. But I will have several Users, so I need a kind of map or array.
Thanks


Top
 Profile  
 
 Post subject: Re: targeting an unmapped class: [java.lang.Boolean]
PostPosted: Fri May 13, 2011 4:12 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
You could have the user state part of the User? Wouldn't this make sense anyways. But of course it depends on your usecase.


Top
 Profile  
 
 Post subject: Re: targeting an unmapped class: [java.lang.Boolean]
PostPosted: Fri May 13, 2011 6:05 am 
Newbie

Joined: Wed Dec 29, 2010 8:58 am
Posts: 10
No, because I need an intermediate entity to keep the history.
My usercase:
Task 1---* TaskHistory *---* User

Then, in TaskHistory I want to have a map with several users containing if they have the task active or not.


Top
 Profile  
 
 Post subject: Re: targeting an unmapped class: [java.lang.Boolean]
PostPosted: Fri May 13, 2011 6:09 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Make out of the Boolean an entity, eg TaskState


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.