1 2 Previous Next 16 Replies Latest reply on Mar 20, 2013 9:09 AM by jaikiran

    Hibernate with jpa

    devi_ks

      Hii ,

      i am using hibernate with jpa. Instead of using annotation to map the entity classes i'm using hibernate mapping file.(hbm file)

      And i specified the mapping file in persistence.xml.

       

      While deploying the war file i have received the mapping exception. (unable to map entities).

       

      Can we use  hibernate mapping file ( hbm file) in persistence.xml ?

       

      Any suggesstions..?

      Thanks in advance..!

        • 1. Re: Hibernate with jpa
          nickarls

          How is the mapping file referenced in persistence.xml? Where is the class file placed in the archive and where does the mapping file end up?

          • 2. Re: Hibernate with jpa
            devi_ks

            Hi Nicklas,

             

            Mapping files are placed in src/main/resources --- META-INF folder. -- Customer.hbm.file

            Classes are placed in src/main/java -  entity package.-- com.dms.entity.CustomerEntity

             

            In Persistence.xml we have a tag named <MappingFile>. In that i have specified the mapping file.

             

            For example, <MappingFile>Customer.hbm.xml</MappingFile>

             

            Thanks..!

            • 3. Re: Hibernate with jpa
              nickarls

              Never tried hbm files but try makeing sure the hbm file ends up in the same package as the entity itself and then refer to the mapping file as foo/bar/Customer.hbm.xml

              • 4. Re: Hibernate with jpa
                devi_ks

                Hi..,

                 

                I had kept the hbm file and the entites in the same package but till i got the entity Mapping exception.

                Can we use hbm mapping file in persistance.xml..?

                 

                ~Thanks.

                • 5. Re: Hibernate with jpa
                  nickarls

                  Show the mapping file

                  • 6. Re: Hibernate with jpa
                    devi_ks

                    Hi Nicklas,

                     

                    Hibernate mapping file

                     

                    <?xml version="1.0"?>

                    <!DOCTYPE hibernate-mapping PUBLIC

                        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

                        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

                     

                    <hibernate-mapping>

                    <class name="com.dms.sample.Customer" table="Customer1" entity-name="Customer1">

                            <id name="CustomerId" column="CUSTOMER_ID" type="java.lang.Integer">

                                <generator class="identity" />

                            </id>

                            <property name="Name" column="CUSTOMER_NAME" type="string"/> 

                            <property name="Age" column="CUSTOMER_AGE" type="java.lang.Integer"/>

                        </class>

                       

                        <class name="com.dms.sample.Customer" table="Customer2" entity-name="Customer2">

                            <id name="CustomerId" column="CUSTOMER_ID" type="java.lang.Integer">

                                <generator class="identity" />

                            </id>

                            <property name="Name" column="CUSTOMER_NAME" type="string"/> 

                            <property name="Age" column="CUSTOMER_AGE" type="java.lang.Integer"/>

                        </class>

                    </hibernate-mapping>

                     

                    Persistence.xml file

                     

                    <?xml version="1.0" encoding="UTF-8"?>

                    <persistence version="2.0"

                       xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence

                            http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

                    <persistence-unit name="hibernateProof" transaction-type="RESOURCE_LOCAL">

                          <provider>org.hibernate.ejb.HibernatePersistence</provider>

                          <non-jta-data-source>java:jboss/datasources/hibernateProofDS</non-jta-data-source>

                          <mapping-file>com/dms/sample/Customer.hbm.xml</mapping-file>

                          <properties>

                                 <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />

                                <property name="hibernate.show_sql" value="true" />

                                <property name="hibernate.format_sql" value="true" />

                                <property name="hibernate.connection.autocommit" value="false"/>

                          </properties>

                       </persistence-unit>

                       </persistence>

                     

                    -Thanks.


                    • 7. Re: Hibernate with jpa
                      nickarls

                      What version of the AS?

                      And both Customer.class and Customer.hbm.xml are in WEB-INF/classes/com/dms/sample ?

                      • 8. Re: Hibernate with jpa
                        devi_ks

                        AS version 7.1.1

                         

                        I am working with maven project. So i kept the Customer.class and Customer.hbm.xml in src/main/java - com/dms/sample package.

                        • 9. Re: Hibernate with jpa
                          nickarls

                          I'm just confirming they end up in the same package in the target class package structure.

                          • 10. Re: Hibernate with jpa
                            devi_ks

                            Ya , ok Nicklas.

                             

                            I need to confirm whether we can specify hbm mapping files in <mapping-file> tag of persistence.xml.

                             

                            Or we have anyother way to map the hibernate mapping file in persistance.xml file.?

                            • 11. Re: Hibernate with jpa
                              jaikiran

                              chitra devi wrote:

                               

                              AS version 7.1.1

                               

                              I am working with maven project. So i kept the Customer.class and Customer.hbm.xml in src/main/java - com/dms/sample package.

                              That doesn't matter at runtime. Those are the build time details. What Nicklas is asking for and what's going to be important is where the files end up in the final deployable. Post the output of:

                               

                              jar -tf yourwar.war

                               

                              where yourwar.war is the name of the war file you are deploying.

                              • 12. Re: Hibernate with jpa
                                devi_ks

                                Hi jai,

                                 

                                Output of the cmd is,

                                 

                                D:\RiskManagement_Workspace\HiberanteConfiguration\target>jar -tf HiberanteConfiguration-1.war

                                META-INF/

                                META-INF/MANIFEST.MF

                                WEB-INF/

                                WEB-INF/classes/

                                WEB-INF/classes/com/

                                WEB-INF/classes/com/dms/

                                WEB-INF/classes/com/dms/sample/

                                WEB-INF/classes/com/dms/ws/

                                WEB-INF/classes/META-INF/

                                WEB-INF/lib/

                                WEB-INF/beans.xml

                                WEB-INF/classes/com/dms/sample/Customer.class

                                WEB-INF/classes/com/dms/sample/CustomerManagerBean.class

                                WEB-INF/classes/com/dms/ws/ServiceCustomer.class

                                WEB-INF/classes/META-INF/Customer.hbm.xml

                                WEB-INF/classes/META-INF/persistence.xml

                                WEB-INF/faces-config.xml

                                WEB-INF/lib/antlr-2.7.6.jar

                                WEB-INF/lib/asm-3.1.jar

                                WEB-INF/lib/cglib-2.2.jar

                                WEB-INF/lib/commons-collections-3.2.1.jar

                                WEB-INF/lib/commons-logging-1.1.1.jar

                                WEB-INF/lib/dom4j-1.6.1.jar

                                WEB-INF/lib/hibernate-annotations-3.5.6-Final.jar

                                WEB-INF/lib/hibernate-commons-annotations-3.2.0.Final.jar

                                WEB-INF/lib/hibernate-core-3.5.6-Final.jar

                                WEB-INF/lib/hibernate-jpa-2.0-api-1.0.0.Final.jar

                                WEB-INF/lib/hibernate3-3.2.3.GA.jar

                                WEB-INF/lib/javax.annotation-api-1.2-b02.jar

                                WEB-INF/lib/javax.ejb-api-3.2-b01.jar

                                WEB-INF/lib/javax.transaction-api-1.2-b01.jar

                                WEB-INF/lib/javax.ws.rs-api-2.0-rc1.jar

                                WEB-INF/lib/javax.xml.rpc-api-1.1.jar

                                WEB-INF/lib/jta-1.1.jar

                                WEB-INF/lib/mysql-connector-java-5.1.9.jar

                                WEB-INF/lib/slf4j-api-1.6.1.jar

                                WEB-INF/lib/xml-apis-1.0.b2.jar

                                WEB-INF/web.xml

                                META-INF/maven/

                                META-INF/maven/ProofOfConcept/

                                META-INF/maven/ProofOfConcept/HiberanteConfiguration/

                                META-INF/maven/ProofOfConcept/HiberanteConfiguration/pom.xml

                                META-INF/maven/ProofOfConcept/HiberanteConfiguration/pom.properties

                                • 13. Re: Hibernate with jpa
                                  nickarls

                                  The class and the hbm file have ended up in different places. Make the mapping file go next to the class.

                                  • 14. Re: Hibernate with jpa
                                    nickarls

                                    Also, I would drop *all* of those bundled jar files (unless you are really using one which isn't provided server-side)

                                    1 2 Previous Next