Fix for Hibernate error “Use of the same entity name twice”

前端 未结 6 952
灰色年华
灰色年华 2020-12-17 17:29

How you fix the following Hibernate error:

What does \"Use of the same entity name twice\".

6条回答
  •  清酒与你
    2020-12-17 17:52

    This exception occures when you have more then one @Entity with the same class's name or explicit name. To fix the issue you have to set different explicit names for each entity.

    Example of error case:

    package A;
    
    @Entity
    class Cell{
     ...   
    }
    
    
    package B;
    
    @Entity
    class Cell{
     ...   
    }
    

    Solution example: package A;

    @Entity(name="a.Cell")
    class Cell{
     ...   
    }
    
    
    package B;
    
    @Entity(name="b.Cell")
    class Cell{
     ...   
    }
    

    So, to use them in HQL you have to write

    ...createQuery("from a.Cell")...
    

提交回复
热议问题