OpenJPA
  1. OpenJPA
  2. OPENJPA-1564

How to Utilizing the variable define in non-entity base class, in the entity sub class.

    Details

    • Type: Question Question
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:

      Description

      I have BaseFacDto class with defined properties. I have sub-class FacDto (entity) extending BaseFacDto.

      public abstract class BaseFacDto

      { @Column(name="FAC_NAME") public String facName; --- }

      @Entity
      @Table(name="FAC")
      public class FacDto extends BaseFacDto implements Serializable {
      public FacDto(){}
      @Id @Column(name="FAC_ID", nullable = false)
      private String facId;
      @Column(name="FAC_ADDRESS")
      private String facAddress;
      @Column(name="LABID")
      }

      Questions:
      1. When the query fac = clep.find(FacDto.class, facId); I don't see FAC_NAME in the logged SQL generated. Since Base class has this variable, so sub-class also get it by inheritance. Please verify. I have define it like this in base class
      @Column(name="FAC_NAME")
      private String facName;

      2. I also tried this thing. I created the variable in the sub-class without getter-setter. Now I see the FAC_NAME in the sql log. But the issue now is when I execute getter methods ( inherited from base class). the value is always null.
      @Column(name="FAC_NAME")
      private String facName;

      3. How OpenJPA different from JPA. I see that all OpenJpa sample uses the javax.persistance.jar (JPA jar). I am little confused over this. Please clarify
      http://openjpa.apache.org/quick-start.html

      Please help.
      Thanks in advance
      Rajeev

        Activity

        Hide
        Donald Woods added a comment -

        Which version of OpenJPA are you using?
        Which database vendor and JDBC driver are you using?

        Show
        Donald Woods added a comment - Which version of OpenJPA are you using? Which database vendor and JDBC driver are you using?
        Hide
        Rajeev Chaudhary added a comment - - edited

        I have weblogic system libraries having javax.persistence_1.0.0.0_1-0.jar and org.apache.openjpa_2.2.0.0_1-1-0.jar.

        Here is the persistance.xml information for the JDBC confi.
        <persistence-unit name="clepDB" transaction-type="RESOURCE_LOCAL">
        <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
        <class>org.wadsworth.eclep.dto.FacDto</class>
        <properties>
        <property name="openjpa.ConnectionURL" value="jdbc:oracle:thin:@lyra:1521:wcdev01"/>
        <property name="openjpa.ConnectionDriverName" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="openjpa.ConnectionUserName" value="clep"/>
        <property name="openjpa.ConnectionPassword" value="clep"/>
        <property name="openjpa.jdbc.Schema" value="CLEP"/>
        <property name="openjpa.ConnectionFactoryProperties" value="PrettyPrint=true, PrettyPrintLineLength=80"/>
        <property name="openjpa.Log" value="SQL=TRACE" />
        </properties>
        </persistence-unit>

        Show
        Rajeev Chaudhary added a comment - - edited I have weblogic system libraries having javax.persistence_1.0.0.0_1-0.jar and org.apache.openjpa_2.2.0.0_1-1-0.jar. Here is the persistance.xml information for the JDBC confi. <persistence-unit name="clepDB" transaction-type="RESOURCE_LOCAL"> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> <class>org.wadsworth.eclep.dto.FacDto</class> <properties> <property name="openjpa.ConnectionURL" value="jdbc:oracle:thin:@lyra:1521:wcdev01"/> <property name="openjpa.ConnectionDriverName" value="oracle.jdbc.driver.OracleDriver"/> <property name="openjpa.ConnectionUserName" value="clep"/> <property name="openjpa.ConnectionPassword" value="clep"/> <property name="openjpa.jdbc.Schema" value="CLEP"/> <property name="openjpa.ConnectionFactoryProperties" value="PrettyPrint=true, PrettyPrintLineLength=80"/> <property name="openjpa.Log" value="SQL=TRACE" /> </properties> </persistence-unit>
        Hide
        Ravi P Palacherla added a comment -

        Hi Rajeev,

        You have a non-persistent super class and you want to persist one of the fields of non-persistence superclass.

        This does not look like possible, as per the documentation:
        http://openjpa.apache.org/builds/latest/docs/manual/manual.html#jpa_overview_pc_restrict_inheritance
        (second bullet point)
        "If a persistent class inherits from a non-persistent class, the fields of the non-persistent superclass cannot be persisted. "

        Regards,
        Ravi.

        Show
        Ravi P Palacherla added a comment - Hi Rajeev, You have a non-persistent super class and you want to persist one of the fields of non-persistence superclass. This does not look like possible, as per the documentation: http://openjpa.apache.org/builds/latest/docs/manual/manual.html#jpa_overview_pc_restrict_inheritance (second bullet point) "If a persistent class inherits from a non-persistent class, the fields of the non-persistent superclass cannot be persisted. " Regards, Ravi.
        Hide
        Rajeev Chaudhary added a comment - - edited

        1. Thanks for the reply on 1 and 2 points.
        2. Expecting reply on third point.
        3. Could you also help me in this situation. I am getting connection object from a third party. I want to used it with JPA to fetch data from database. How to go for this.

        Show
        Rajeev Chaudhary added a comment - - edited 1. Thanks for the reply on 1 and 2 points. 2. Expecting reply on third point. 3. Could you also help me in this situation. I am getting connection object from a third party. I want to used it with JPA to fetch data from database. How to go for this.
        Hide
        Donald Woods added a comment -

        Original third point - OpenJPA 1.x implements the JPA 1.0 Spec API, while OpenJPA 2.0 implements the JPA 2.0 Spec API.
        For OpenJPA 1.0/1.1/1.2, you can also use the JPA 1.0 Spec API jar from the Apache Geronimo project - geronimo-jpa_1.0_spec-1.1.2.jar , whereas we've already switched to the Geronimo version for 1.3/2.0.

        Show
        Donald Woods added a comment - Original third point - OpenJPA 1.x implements the JPA 1.0 Spec API, while OpenJPA 2.0 implements the JPA 2.0 Spec API. For OpenJPA 1.0/1.1/1.2, you can also use the JPA 1.0 Spec API jar from the Apache Geronimo project - geronimo-jpa_1.0_spec-1.1.2.jar , whereas we've already switched to the Geronimo version for 1.3/2.0.
        Hide
        Ravi P Palacherla added a comment -

        Can you please elaborate on "I am getting connection object from a third party."
        I think you are using Connection details in persistence.xml, so what do you mean "I am getting connection object from a third party. I want to used it with JPA to fetch data from database. ?"

        Show
        Ravi P Palacherla added a comment - Can you please elaborate on "I am getting connection object from a third party." I think you are using Connection details in persistence.xml, so what do you mean "I am getting connection object from a third party. I want to used it with JPA to fetch data from database. ?"
        Hide
        Ravi P Palacherla added a comment -

        May be you are talking about the following:
        http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_dbsetup_builtin
        Please check #2 and 2.1 in the above link.

        Show
        Ravi P Palacherla added a comment - May be you are talking about the following: http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_dbsetup_builtin Please check #2 and 2.1 in the above link.
        Hide
        Rajeev Chaudhary added a comment -

        Thanks for the reply. Let me explain in steps

        1. I have a servlet filter which dynamically generate the DataSource based on some config parameters, create and set connection object in the request.

        2. I am getting this connection object and I want to use this connection object with the JPA entity classes which I have created. How can I do it. I don't want to write basic sql steps to fetch data from database.

        3. Currently I have hard coded the datasource name in the persistance.xml and utilizing it to interact with the Database with the entity classes, entity Manager.

        Please help.

        Show
        Rajeev Chaudhary added a comment - Thanks for the reply. Let me explain in steps 1. I have a servlet filter which dynamically generate the DataSource based on some config parameters, create and set connection object in the request. 2. I am getting this connection object and I want to use this connection object with the JPA entity classes which I have created. How can I do it. I don't want to write basic sql steps to fetch data from database. 3. Currently I have hard coded the datasource name in the persistance.xml and utilizing it to interact with the Database with the entity classes, entity Manager. Please help.
        Hide
        Rajeev Chaudhary added a comment -

        To Inherit the properties of a base class, we only add "@MappedSuperclass" as shown below. Also this class BaseFacDto should also be defined in the persistance.xml.
        @MappedSuperclass
        public abstract class BaseFacDto implements Serializable{

        }

        Show
        Rajeev Chaudhary added a comment - To Inherit the properties of a base class, we only add "@MappedSuperclass" as shown below. Also this class BaseFacDto should also be defined in the persistance.xml. @MappedSuperclass public abstract class BaseFacDto implements Serializable{ }

          People

          • Assignee:
            Unassigned
            Reporter:
            Rajeev Chaudhary
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 24h
              24h
              Remaining:
              Remaining Estimate - 24h
              24h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development