Hibernate primary key violation on two server instances - java

I have an application which is running on two servers and both these servers access the same database via Hibernate.
The issue here is when these two applications process large set of data and trying to insert to the same table. There is a primary key violation happens. And from the things I have noticed, hibernate seems to buffer some number of primary key ids. eg. If server A insert data into id 100 and at the same time server B will be inserting to id 200 or so. I guess this issue is related to above mentioned scenario. Following is my hibernate properties
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/dbtest?autoReconnect=true</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">password</property>
<!-- <property name="hibernate.show_sql">true</property>-->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!--
<property name="hibernate.hbm2ddl.auto">update</property>
-->
<property name="hibernate.use_sql_comments">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.connection.zeroDateTimeBehavior">convertToNull</property>
<property name="hibernate.connection.isolation">2</property>
<property name="hibernate.default_schema">dbtest</property>
<property name="hibernate.jdbc.batch_size">50</property>
<!--c3po connection pooling -->
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
This is the entity which is failing
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Sep 3, 2014 4:38:39 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.test.dto.AdditionalContacts" table="additional_contacts"
entity-name="additionalcontacts">
<id name="contactId" type="java.lang.Integer" column="contactId">
<generator class="increment" />
</id>
<property name="contactGuid" type="java.lang.String">
<column name="contactGuid" />
</property>
<property name="contactName" type="java.lang.String">
<column name="contactName" />
</property>
<property name="salutation" type="java.lang.String">
<column name="salutation" />
</property>
<property name="EmailAddress" type="java.lang.String">
<column name="email" />
</property>
<property name="includeInEmails" type="java.lang.Boolean">
<column name="includeInEmails" />
</property>
<property name="Website" type="java.lang.String">
<column name="website" />
</property>
<property name="city" type="java.lang.String">
<column name="city" />
</property>
<property name="state" type="java.lang.String">
<column name="state" />
</property>
<property name="postCode" type="java.lang.String">
<column name="postCode" />
</property>
<property name="country" type="java.lang.String">
<column name="country" />
</property>
<property name="street" type="java.lang.String">
<column name="street" />
</property>
<property name="streetLine1" type="java.lang.String">
<column name="streetLine1" />
</property>
<property name="streetLine2" type="java.lang.String">
<column name="streetLine2" />
</property>
<property name="streetLine3" type="java.lang.String">
<column name="streetLine3" />
</property>
<property name="streetLine4" type="java.lang.String">
<column name="streetLine4" />
</property>
<property name="phone1" type="java.lang.String">
<column name="phone1" />
</property>
<property name="phone2" type="java.lang.String">
<column name="phone2" />
</property>
<property name="phone3" type="java.lang.String">
<column name="phone3" />
</property>
<property name="fax" type="java.lang.String">
<column name="fax" />
</property>
<property name="location" type="java.lang.String">
<column name="location" />
</property>
<property access="field" column="createDate" insert="true"
name="createDate" update="false" />
<property access="field" column="modifyDate" insert="true"
name="modifyDate" update="true" />
</class>
</hibernate-mapping>
And following is the entity which uses above entity
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Sep 3, 2014 4:38:39 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.test.dto.Contacts" table="contact"
entity-name="contact">
<id name="cGuid" type="java.lang.String">
<column name="contactGuid" />
</id>
<property name="org" type="java.lang.Integer">
<column name="org" />
</property>
<property name="Name" type="java.lang.String">
<column name="name" />
</property>
<property name="FirstName" type="java.lang.String">
<column name="firstName" />
</property>
<property name="LastName" type="java.lang.String">
<column name="lastName" />
</property>
<property name="abn" type="java.lang.String">
<column name="abn" />
</property>
<property name="active" type="java.lang.Boolean">
<column name="active" />
</property>
<property access="field" column="createDate" insert="true"
name="createDate" update="false" />
<property access="field" column="modifyDate" insert="true"
name="modifyDate" update="true" />
<bag name="additionalContactList" table="additional_contact" lazy="false" inverse="true"
cascade="all">
<key>
<column name="contactGuid" not-null="true" />
</key>
<one-to-many entity-name="additionalcontacts"
class="com.test.dto.AdditionalContact" />
</bag>
</class>
</hibernate-mapping>
This one is failing on
cascade="all"

You need to use AUTO_INCREMENT. This way MySQL will manage the creation of IDs, so the servers won't have to synchronize. Change the DB column to be AUTO_INCREMENT. In Hibernate change the generator type to native.
Other alternatives would be to use UUID as the primary key.
Newer versions of Hibernate have other generators that can be used that are better than native.

Related

OGM and ORM named queries in xml file

My application contains both ORM and OGM. For ORM I was wrote some named queries in xyz.hbm.xml. But while using OGM those queries caused for exception. I am using OGM 4.1.3.Final version. Please help someone.
example.hbm.xml
<?xml version="1.0" ?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jan 1, 2015 1:53:57 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="mkcl.os.apps.edumiss.model.student.Admission" table="ADMISSION">
<id name="id" type="java.lang.String">
<column name="ADMISSION_ID" />
<generator class="uuid" />
</id>
<property name="studentId">
<column name="STUDENTID" />
</property>
<property name="schoolId">
<column name="SCHOOL_ID" />
</property>
<property name="academicYearId" type="int">
<column name="ACADEMICYEARID" />
</property>
<property name="sectionRollNumber" type="int">
<column name="SECTIONROLLNUMBER" />
</property>
<property name="admissionDate" type="java.util.Date">
<column name="ADMISSIONDATE" />
</property>
<property name="schoolLeavingDate" type="java.util.Date">
<column name="SCHOOL_LEAVING_DATE" />
</property>
<property name="standardId" type="short">
<column name="STANDARDID" />
</property>
<property name="standardName" type="java.lang.String">
<column name="STANDARD_NAME" />
</property>
<property name="sectionId">
<column name="SECTION_ID" />
</property>
<property name="sectionName">
<column name="SECTION_NAME" />
</property>
<property name="reasonForLeaving">
<column name="REASON_FOR_LEAVING" />
</property>
<property name="streamId" type="short">
<column name="STREAM_ID" />
</property>
<property name="streamName" type="java.lang.String">
<column name="STREAM_NAME" />
</property>
<property name="admissionType" column="ADMISSION_TYPE">
<type name="org.hibernate.type.EnumType">
<param name="useNamed"></param>
<param name="enumClass">mkcl.os.apps.edumiss.model.student.AdmissionType</param>
</type>
</property>
<property name="createdBy" type="java.lang.String">
<column name="CREATED_BY" />
</property>
<property name="createOn" type="java.util.Date">
<column name="CREATED_ON" />
</property>
<property name="modifiedBy" type="java.lang.String">
<column name="MODIFIED_BY" />
</property>
<property name="lastModified" type="java.util.Date">
<column name="LAST_MODIFIED" />
</property>
<property name="patternId" type="integer">
<column name="PATTERN_ID"></column>
</property>
</class>
<sql-query name="getAdmissionForAcademicYear">
<return alias="admission" class="mkcl.os.apps.edumiss.model.student.Admission"></return>
<![CDATA[
SELECT
{admission.*}
FROM
ADMISSION admission
INNER JOIN STUDENT s
ON
s.CURRENT_ADMISSION_ID = admission.ADMISSION_ID
WHERE
admission.STUDENTID = :mkclIdentificationNumber
AND
admission.ACADEMICYEARID = :academicYearId
]]>
</sql-query>
</hibernate-mapping>
this throws
java.lang.IncompatibleClassChangeError: class org.objectweb.asm.tree.ClassNode has interface org.objectweb.asm.ClassVisitor as super class
if I am removing above query from hbm file then it worked fine. But I have to keep those queries in .hbm.xml file as it is.
That query is for a relational database, so you don't need the OGM for that.
Why do you want to run an SQL query against OGM, which is for NoSQL?
The default hibernate.archive.autodetection property value is class,hbm, so make sure you set it to class in the persistence.xml file that's associated to the OGM EntityManagerFactory. You do have two separate persistence.xml configurations (one for ORM and one for OGM), right?
according to current version of OGM(5.0) feature document:
Model can not possible to share between OGM and ORM together and this will projected to resolve in next version of OGM.
ORM classes can try to parse the .hbm.xml file and find the named queries which having the syntax of mongo query. so while reading the file OGM unable to parse the syntax of SQL named query and throws an error so I have only way to shift the all the queries into another hbm whose wntry will not be present in nosql_hibernate.xml file so OGM will not parse and my code will run fast else till this feature not support shift to another framework.

Hibernate order-by removing rows

I have a one-to-Many Set defined in my mapping file, and when I use the order-by property the data in the Set will be missing rows depending on what property I use to order.
<hibernate-mapping>
<class name="domain.StudentUser" table="student_user" >
....
<set name="studentCourseses" inverse="true" order-by="import_date ASC">
<key>
<column name="student_userid" length="15" not-null="true" />
</key>
<one-to-many class="domain.StudentCourses" />
</set>
</hibernate-mapping>
public StudentUser findById(java.lang.String id) {
log.debug("getting StudentUser instance with id: " + id);
try {
StudentUser instance = (StudentUser) getSession().get(
"domain.StudentUser", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
Here i use import_date, but this table has about 15 properties and certain properties will cause rows to be missing from the Set while others don't. It doesn't seem to be data-type specific as I have the issue with a String property but then another String property will work fine and all data will be there. It is always the same rows that are missing no matter the sorting property used, so its not random rows.
The majority of the student_user have data missing, but not all. The rows that end up missing have nothing abnormal about them, meaning no NULL's or anything like that.
As of this point, i just removed the order-by attribute so I can get my app working property, but I still need to know why these issues are happening. So far I have not noticed this behavior in any of the other Set's that i use the order-by attribute with, just this one.
I am using Hibernate 3.5.3 and in case it's helpful, here is the mapping file for the StudentCourses table
<hibernate-mapping>
<class name="domain.StudentCourses" table="student_courses" >
<id name="id" type="integer">
<column name="id" />
<generator class="native" />
</id>
<many-to-one name="classLevel" class="domain.ClassLevel" fetch="select">
<column name="class_level_code" length="2" not-null="true" />
</many-to-one>
<many-to-one name="academicTerm" class="domain.AcademicTerm" fetch="select">
<column name="academic_term_id" not-null="true" />
</many-to-one>
<many-to-one name="studentUser" class="domain.StudentUser" fetch="select">
<column name="student_userid" length="15" not-null="true" />
</many-to-one>
<property name="academicYear" type="integer">
<column name="academic_year" not-null="true" />
</property>
<property name="term" type="string">
<column name="term" length="8" not-null="true" />
</property>
<property name="title" type="string">
<column name="title" length="64" not-null="true" />
</property>
<property name="prefix" type="string">
<column name="prefix" length="8" not-null="true" />
</property>
<property name="courseNum" type="string">
<column name="course_num" length="8" not-null="true" />
</property>
<property name="suffix" type="string">
<column name="suffix" length="8" />
</property>
<property name="sectionNum" type="string">
<column name="section_num" length="8" />
</property>
<property name="units" type="double">
<column name="units" precision="4" not-null="true" unique="true" />
</property>
<property name="letterGrade" type="string">
<column name="letter_grade" length="6" not-null="true" />
</property>
<property name="qtrGpa" type="double">
<column name="qtr_gpa" precision="4" scale="3" not-null="true" />
</property>
<property name="cumGpa" type="double">
<column name="cum_gpa" precision="4" scale="3" not-null="true" />
</property>
<property name="importDate" type="timestamp">
<column name="import_date" length="19" />
</property>
<property name="sourceFileName" type="string">
<column name="source_file_name" length="128" />
</property>
<property name="timeStamp" type="timestamp">
<column name="time_stamp" length="19" not-null="true">
<comment>on update CURRENT_TIMESTAMP</comment>
</column>
</property>
</class>
Update (More Info):
If i directly query the StudentCourses table (CORRECT) vs getting the StudentCourses data from the StudentUser mapping set (INCORRECT) gives me different results, they should match
for(StudentCourses course : getStudentService().retrieveStudentByID("861043440").getStudentCourseses()) { //MISSING DATA
System.out.println(course +" - "+course.getTerm());
}
for(StudentCourses course : (List<StudentCourses>)getStudentService().getStudentCoursesDAO().findByProperty("studentUser.studentUserid", "861043440")) { //ALL DATA CORRECT
System.out.println(course +" - "+course.getTerm());
}
Turns out it had nothing to do with sorting, as adjusting the sorting only fixed the issue for some but not all. The problem was that I had overriden the hashCode method of the StudentCourses object and it was causing collisions when the Set was being populated from the StudentUser object. I fixed this and everything is good now.

Hibernate4 XML named query not known

I have this hbm file just to test/practice how to use a named sql in an xml file but it gives me "Named query not known: testQuery1"
public List<Meb_item> namedList() {
// TODO Auto-generated method stub
Session session = sessionFactory.getCurrentSession();
return session.getNamedQuery("testQuery1").list();
}
<hibernate-mapping>
<class table="SIDEEFFECT.MEB_ITEM" name="foreign.Meb_item">
<id name="meddev_item_seq">
<column name="MEDDEV_ITEM_SEQ"/>
</id>
<resultset name="testRs">
<return class="foreign.Meb_item">
<return-property name="item_name" column="item_name"></return-property>
</return>
</resultset>
<sql-query name="testQuery1" callable="true" >
select * from meb_item
<return class="foreign.Meb_item" >
<return-property name="item_name" column="item_name"></return-property>
</return>
</sql-query>
</class>
And here is part of my hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<mapping resource="mea_class_no.hbm.xml"/>
<mapping resource="mea_compay.hbm.xml"/>
<mapping resource="meb_item.hbm.xml"/>
</session-factory>
</hibernate-configuration>
I've consulted JBoss documents but I could not find what was wrong.
Why does it say the named query is not known ?
I figured it out.
The sql-query tag seems to be sensitive to the position in the mapping document.
I moved it from the inside of the class tag to outside of it.
Now it seems to be called as expected. Though it prompts another error.
Here is the whole 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 table="SIDEEFFECT.MEB_ITEM" name="foreign.Meb_item">
<id name="meddev_item_seq">
<column name="MEDDEV_ITEM_SEQ"/>
</id>
<property name="machinery_area_code">
<column name="MACHINERY_AREA_CODE"/>
</property>
<property name="cob_flag_code">
<column name="COB_FLAG_CODE"/>
</property>
<property name="permit_state_code">
<column name="PERMIT_STATE_CODE"/>
</property>
<property name="meddev_item_no">
<column name="MEDDEV_ITEM_NO"/>
</property>
<property name="tax_no">
<column name="TAX_NO"/>
</property>
<property name="item_name">
<column name="ITEM_NAME"/>
</property>
<property name="permit_date">
<column name="PERMIT_DATE"/>
</property>
<property name="manuf_country_code">
<column name="MANUF_COUNTRY_CODE"/>
</property>
<property name="manuf_name">
<column name="MANUF_NAME"/>
</property>
<property name="manuf_place">
<column name="MANUF_PLACE"/>
</property>
<property name="manuf_req_country_code">
<column name="MANUF_REQ_COUNTRY_CODE"/>
</property>
<property name="manuf_req_name">
<column name="MANUF_REQ_NAME"/>
</property>
<property name="manuf_req_place">
<column name="MANUF_REQ_PLACE"/>
</property>
<property name="seller_country_code">
<column name="SELLER_COUNTRY_CODE"/>
</property>
<property name="seller_name">
<column name="SELLER_NAME"/>
</property>
<property name="seller_place">
<column name="SELLER_PLACE"/>
</property>
<property name="manuf_import_entp_name">
<column name="MANUF_IMPORT_ENTP_NAME"/>
</property>
<property name="manuf_import_zip_no">
<column name="MANUF_IMPORT_ZIP_NO"/>
</property>
<property name="manuf_import_addr1">
<column name="MANUF_IMPORT_ADDR1"/>
</property>
<property name="manuf_import_addr2">
<column name="MANUF_IMPORT_ADDR2"/>
</property>
<property name="cancel_withdw_code">
<column name="CANCEL_WITHDW_CODE"/>
</property>
<property name="cancel_withdw_date">
<column name="CANCEL_WITHDW_DATE"/>
</property>
<property name="shape">
<column name="SHAPE"/>
</property>
<property name="sumr_name">
<column name="SUMR_NAME"/>
</property>
<property name="size_cnt">
<column name="SIZE_CNT"/>
</property>
<property name="chart_name">
<column name="CHART_NAME"/>
</property>
<property name="make_method">
<column name="MAKE_METHOD"/>
</property>
<property name="use_purpose">
<column name="USE_PURPOSE"/>
</property>
<property name="use_method">
<column name="USE_METHOD"/>
</property>
<property name="nb">
<column name="NB"/>
</property>
<property name="valid_term">
<column name="VALID_TERM"/>
</property>
<property name="exam_std">
<column name="EXAM_STD"/>
</property>
<property name="permit_cond">
<column name="PERMIT_COND"/>
</property>
<property name="remark">
<column name="REMARK"/>
</property>
<property name="meddev_entp_seq">
<column name="MEDDEV_ENTP_SEQ"/>
</property>
<property name="mea_class_no">
<column name="MEA_CLASS_NO"/>
</property>
<property name="grade">
<column name="GRADE"/>
</property>
<property name="receipt_no">
<column name="RECEIPT_NO"/>
</property>
<property name="bef_doc_id">
<column name="BEF_DOC_ID"/>
</property>
<property name="safe_exam_yn">
<column name="SAFE_EXAM_YN"/>
</property>
<property name="export_dev_yn">
<column name="EXPORT_DEV_YN"/>
</property>
<property name="same_goods_yn">
<column name="SAME_GOODS_YN"/>
</property>
<property name="same_item_no">
<column name="SAME_ITEM_NO"/>
</property>
<property name="storage_method">
<column name="STORAGE_METHOD"/>
</property>
<property name="material">
<column name="MATERIAL"/>
</property>
<property name="mention_cont">
<column name="MENTION_CONT"/>
</property>
<property name="regist_ts">
<column name="REGIST_TS"/>
</property>
<property name="regist_id">
<column name="REGIST_ID"/>
</property>
<property name="update_ts">
<column name="UPDATE_TS"/>
</property>
<property name="update_id">
<column name="UPDATE_ID"/>
</property>
<property name="serv_target">
<column name="SERV_TARGET"/>
</property>
<property name="trace_manage_target_yn">
<column name="TRACE_MANAGE_TARGET_YN"/>
</property>
<property name="reexam_yn">
<column name="REEXAM_YN"/>
</property>
<property name="reexam_valid_start_date">
<column name="REEXAM_VALID_START_DATE"/>
</property>
<property name="reexam_valid_end_date">
<column name="REEXAM_VALID_END_DATE"/>
</property>
<property name="serv_target2">
<column name="SERV_TARGET2"/>
</property>
<property name="bef_cancel_withdw_code">
<column name="BEF_CANCEL_WITHDW_CODE"/>
</property>
<property name="issue_org_code">
<column name="ISSUE_ORG_CODE"/>
</property>
<property name="class_change_yn">
<column name="CLASS_CHANGE_YN"/>
</property>
<property name="delete_yn">
<column name="DELETE_YN"/>
</property>
<property name="material_ver">
<column name="MATERIAL_VER"/>
</property>
<property name="disposable_emed_yn">
<column name="DISPOSABLE_EMED_YN"/>
</property>
</class>
<sql-query name="testQuery1" >
<return class="foreign.Meb_item" >
<return-property name="item_name"><return-column name="item_name"/></return-property>
</return>
SELECT ITEM_NAME FROM MEB_ITEM
</sql-query>
</hibernate-mapping>
I hope it helps :)

getting error while trying to map view to hibernate entities

I created a view.
CREATE VIEW VW_LOSA_APP_PENDING AS
SELECT distinct app.APP_REF_NO, app.APP_STATUS, app.APP_DT, app.ATTEND_STAFF,
app.ATTEND_BRANCH, app.PRODUCT_TYPE APP_PRODUCT_TYPE,
cust.CUST_ID, cust.APP_JOINT_T, cust.ID1_TYPE, cust.ID1,
cust.ID2_TYPE, cust.ID2, cust.FIRST_NAME, cust.LAST_NAME,
cust.FULL_NAME, cust.FULL_NAME_CAP, cust.DOB, fac.FACILITY_NO,
fac.PRODUCT_TYPE FAC_PRODUCT_TYPE, fac.PRODUCT_CODE,
fac.MAIN_PROD_IND, fac.AMT_APPLIED
FROM
LOSA_APP app
LEFT JOIN
LOSA_CUST cust
ON
cust.APP_REF_NO = app.APP_REF_NO
LEFT JOIN
LOSA_FACILITIES fac
ON
fac.APP_REF_NO = app.APP_REF_NO
LEFT JOIN
OS_CURRENTSTEP STEP
ON
STEP.REF_ID = app.APP_REF_NO
WHERE (app.APP_STATUS ='P' OR app.APP_STATUS ='T' OR
((app.APP_STATUS='R' OR app.APP_STATUS='S') AND STEP.STEP_NAME='011'));
Now i am trying to map this view to hibernate file. But i am getting error that
Here how i am defining my mapping
<hibernate-mapping default-lazy="false">
<class name="com.thetasp.losa.data.VwLosaAppPending" table="VW_LOSA_APP_PENDING" optimistic-lock="version">
<property name="appRefNo" type="java.lang.String" column="APP_REF_NO" not-null="true" length="20" />
<property name="appStatus" type="java.lang.String" column="APP_STATUS" length="20" />
<property name="appDt" type="java.sql.Timestamp" column="APP_DT" not-null="true" length="23" />
<property name="attendStaff" type="int" column="ATTEND_STAFF" not-null="true" length="10" />
<property name="attendBranch" type="int" column="ATTEND_BRANCH" not-null="true" length="10" />
<property name="appProductType" type="java.lang.String" column="APP_PRODUCT_TYPE" length="10" />
<property name="custId" type="java.lang.String" column="CUST_ID" length="20" />
<property name="appJointT" type="java.lang.String" column="APP_JOINT_T" length="10" />
<property name="id1Type" type="java.lang.String" column="ID1_TYPE" length="1" />
<property name="id1" type="java.lang.String" column="ID1" length="20" />
<property name="id2Type" type="java.lang.String" column="ID2_TYPE" length="1" />
<property name="id2" type="java.lang.String" column="ID2" length="20" />
<property name="firstName" type="java.lang.String" column="FIRST_NAME" length="100" />
<property name="lastName" type="java.lang.String" column="LAST_NAME" length="100" />
<property name="fullName" type="java.lang.String" column="FULL_NAME" length="250" />
<property name="fullNameCap" type="java.lang.String" column="FULL_NAME_CAP" length="250" />
<property name="dob" type="java.sql.Date" column="DOB" length="23" />
<property name="facilityNo" type="java.lang.Long" column="FACILITY_NO" />
<property name="facProductType" type="java.lang.String" column="FAC_PRODUCT_TYPE" length="10" />
<property name="productCode" type="java.lang.String" column="PRODUCT_CODE" length="20" />
<property name="mainProdInd" type="java.lang.String" column="MAIN_PROD_IND" length="1" />
<property name="amtApplied" column="AMT_APPLIED" length="18">
<type name="com.thetasp.common.hibernate.support.ParameterizedDoubleType" />
</property>
</class>
I am getting error at line
<class name="com.thetasp.losa.data.VwLosaAppPending" table="VW_LOSA_APP_PENDING" optimistic-lock="version">
Why i am getting this error? What i am doing wrong ?
Thanks
The message is:
The content of element type "class" must match "([...], (id, composite-id), [...])
You don't have any id or composite-id element in your class definition.

Hibernate not Loading a class

I have a class Auction that contains a Class Item and Users but when I am getting the class, the class item and Users are not being loaded.
Auction Class Mapping File:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 28, 2010 9:14:12 PM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
<class name="com.BiddingSystem.Models.Auction" table="AUCTION">
<id name="AuctionId" type="long">
<column name="AUCTIONID" />
<generator class="native" />
</id>
<property name="StartTime" type="java.util.Date">
<column name="STARTTIME" />
</property>
<property name="EndTime" type="java.util.Date">
<column name="ENDTIME" />
</property>
<property name="StartingBid" type="long">
<column name="STARTINGBID" />
</property>
<property name="MinIncrement" type="long">
<column name="MININCREMENT" />
</property>
<many-to-one name="CurrentItem" class="com.BiddingSystem.Models.Item" fetch="join" cascade="all">
<column name="ItemId" />
</many-to-one>
<property name="AuctionStatus" type="java.lang.String">
<column name="AUCTIONSTATUS" />
</property>
<property name="BestBid" type="long">
<column name="BESTBID" />
</property>
<many-to-one name="User" class="com.BiddingSystem.Models.Users" fetch="join">
<column name="UserId" />
</many-to-one>
</class>
</hibernate-mapping>
When I am doing this:
Query query=session.createQuery("from Auction where UserId="+UserId);
List <Auction> AllAuctions= new LinkedList<Auction>(query.list());
The Users and Item are null
#ManyToOne(fetch=FetchType.EAGER) would be the annotation based configuration element you are missing. Please refer to the manual to see how to configure this by XML.

Categories