[ 
https://issues.apache.org/jira/browse/OPENJPA-414?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Richard Zowalla resolved OPENJPA-414.
-------------------------------------
    Resolution: Won't Fix

Closing as obsolete during backlog cleanup: The posted sample does not compile 
(hashCode uses an uninitialized 'result' and has no return) and there is no 
runnable reproducer; JOINED inheritance with XML mappings is covered by the 
current test suite. Please reopen if this still happens with OpenJPA 4.x.

> Null id's in entyties while using Joined inheritance strategy
> -------------------------------------------------------------
>
>                 Key: OPENJPA-414
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-414
>             Project: OpenJPA
>          Issue Type: Bug
>    Affects Versions: 1.0.0
>            Reporter: Alexander Filipchik
>            Priority: Blocker
>
> I use inheritance in that way:
> Parent class:
> public class State implements Serializable {
>       private static final long serialVersionUID = -380133999593231293L;
>       private long stateId;   
>       
>       public State() {                
>       }
>       
>       public long getStateId() {
>               return stateId;
>       }
>       public void setStateId(long stateId) {
>               this.stateId = stateId;
>       }
>       
>       @Override
>       public boolean equals(Object obj) {
>         if (this == obj) return true;
>         if (obj == null || getClass() != obj.getClass()) return false;
>         State that = (State) obj;      
>         if (stateId!=that.stateId) return false;
>         return true;
>       }
>       @Override
>       public int hashCode() {
>         int result;
>         result = 31 * result + (int) (stateId ^ (stateId >>> 32));
>       }       
> }
> <?xml version="1.0" encoding="UTF-8"?>
> <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"; 
> version="1.0">
>       <package>xxx</package>  
>       <entity class="State" name="State">
>               <table name="REG_STATUS" />
>               <inheritance strategy="JOINED"/>                
>               <attributes>
>                       <id name="stateId">
>                               <column name="STATUS_ID"/> 
>                       </id>
>               </attributes>
>       </entity>
> it has 1 child class:
> public class RCategory extends State implements Serializable {
>     private static final long serialVersionUID = 2472570459234097349L;
>     private RCategory parentCategory;
>     private String title;
>     private String description;
>     private Set<RCategory> children;
>     private boolean containsChildren;
>     private Long id;
>     public RCategory() {
>     }
>     public RCategory(Long id, String title) {
>         setId(id);
>         this.title = title;
>         this.containsChildren = false;
>     }
>     public RCategory(Long id, String title, boolean containsChildren) {
>         setId(id);
>         this.title = title;
>         this.containsChildren = containsChildren;
>     }
>     public String getDescription() {
>         return description;
>     }
>     public void setDescription(String description) {
>         this.description = description;
>     }
>     public String getTitle() {
>         return this.title;
>     }
>     public Long getId() {
>         return id;
>     }
>     public void setId(Long id) {
>         System.out.println("---------------------Setting 
> id-------------------");
>         System.out.println(id);
>         this.id = id;
>     }
>     public void setTitle(String title) {
>         this.title = title;
>     }
>     public Set<RCategory> getChildren() {
>         return children;
>     }
>     public void setChildren(Set<RCategory> children) {
>         this.children = children;
>     }
>     public RCategory getParentCategory() {
>         return parentCategory;
>     }
>     public void setParentCategory(RCategory parentCategory) {
>         this.parentCategory = parentCategory;
>     }
>     public boolean isContainsChildren() {
>         return containsChildren;
>     }
>     public void setContainsChildren(boolean containsChildren) {
>         this.containsChildren = containsChildren;
>     }
>     public boolean equals(Object o) {
>         if (this == o) return true;
>         if (o == null || getClass() != o.getClass()) return false;
>         if (!super.equals(o)) return false;
>         RCategory rCategory = (RCategory) o;
>         if (id != null ? !id.equals(rCategory.id) : rCategory.id != null) 
> return false;
>         if (title != null ? !title.equals(rCategory.title) : rCategory.title 
> != null) return false;
>         return true;
>     }
>     public int hashCode() {
>         int result = super.hashCode();
>         result = 31 * result + (title != null ? title.hashCode() : 0);
>         result = 31 * result + (id != null ? id.hashCode() : 0);
>         return result;
>     }
> }
> <?xml version="1.0" encoding="UTF-8"?>
> <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm";
>                  version="1.0">
>     <package>xxx</package>
>     <entity class="RCategory" name="RCategory">
>         <table name="reg_r_category"/>
>         <primary-key-join-column name="R_CATEGORY_ID" 
> referenced-column-name="STATUS_ID"/>
>         <post-load method-name="prinf"/>
>         <attributes>
>             <id name="id">
>                 <column name="R_CATEGORY_ID"/>
>             </id>
>             <basic name="title">
>                 <column length="256" name="TITLE" nullable="false"/>
>             </basic>
>             <basic name="description">
>                 <column length="512" name="DESCRIPTION" nullable="false"/>
>             </basic>
>             <basic name="containsChildren">
>                 <column name="CONTAIN_SUBCATEGORIES"/>
>             </basic>
>             <many-to-one name="parentCategory" target-entity="RCategory">
>                 <join-column name="PARENT_CATEGORY_ID" insertable="true" 
> updatable="true"/>
>                 <cascade>
>                     <cascade-merge/>
>                     <cascade-refresh/>
>                 </cascade>
>             </many-to-one>
>             <one-to-many mapped-by="parentCategory" name="children" 
> target-entity="RCategory">
>                 <order-by>title</order-by>
>                 <cascade>
>                     <cascade-all/>
>                 </cascade>
>             </one-to-many>
>         </attributes>
>     </entity>
> When i use getReference on RCategory - i get object with NULL!!!! id. 
> Also, when i use find, i get object with null id too, but i can use it in 
> references (add to another object and persist)



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to