Results 1 to 2 of 2

Thread: @ManyToOne exception

  1. #1
    Join Date
    Jul 2011
    Posts
    19

    Default @ManyToOne exception

    I'm receiving the following exception and have looked around to understand what may be wrong but just don't understand what I'm doing wrong. My main attempt is to properly represent foreign key in Agent that refers to Minor_Stage_Configuration table FDS_Minor_Stage_Configuration_ID. I've read the documentation but don't fully understand how the two entities know about each other.

    Code:
    Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on net.fractech.ops.fds.db.Agent.minorStageConfigIdFK references an unknown entity: int
    	at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:107)
    	at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1580)
    	at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1503)
    	at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1419)
    	at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375)
    	at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1519)
    	at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
    	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1100)
    	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:689)
    	at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
    	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:242)
    	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1479)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
    	... 20 more
    Agent.java
    Code:
    @Entity
    @Table(name="Agent")
    public class Agent implements Serializable
    {
       private int minorStageConfigIdFK;
    
       // the element name for this element in the table is Minor_Stage_Configuration_ID_FK
       @NotNull
       @ManyToOne
       @JoinColumn(name="Minor_Stage_Configuration_ID_FK")
       public int getMinorStageConfigIdFK()  {  return(this.minorStageConfigIdFK);  }
    
       public void setMinorStageConfigIdFK(final int minorStageConfigIdFK_)   {     this.minorStageConfigIdFK = minorStageConfigIdFK_;  }
    
    // rest of code}
    MinorStageConfig.java
    Code:
    @Entity
    @Table(name="Minor_Stage_Configuration")
    public class MinorStageConfig implements Serializable
    {
       private List<Agent> agentList;
       private int id;
       private int minorStageIdFK;
    
       @OneToMany(mappedBy="minorStageConfigIdFK", targetEntity=Agent.class)
       public List<Agent> getAgentList()   {  return(this.agentList);  }
    
       public void setAgentList(final List<Agent> agentList_) { this.agentList = agentList_; }
    
       @Id
       @GeneratedValue(strategy=GenerationType.AUTO)
       @NotNull
       @Column(name="FDS_Minor_Stage_Configuration_ID")
       public int getId()  { return(this.id); }
    
       public void setId(final int id_)  {  this.id = id_; }
    
    // rest of code}

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Hello

    I suggest you read again about mappings and relations with JPA/Hibernate

    The error is clear

    Code:
    Caused by: 
    org.hibernate.AnnotationException: 
    @OneToOne or @ManyToOne on 
    net.fractech.ops.fds.db.Agent.minorStageConfigIdFK 
    references an unknown entity: int
    This is wrong

    Code:
     
    public int getMinorStageConfigIdFK()  {  return(this.minorStageConfigIdFK);  }
    
    public void setMinorStageConfigIdFK(final int minorStageConfigIdFK_)   {     this.minorStageConfigIdFK = minorStageConfigIdFK_;  }
    Instead of int you must use MinorStageConfig, again read Hibernate documentation
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •