Please find my two tables
CREATE TABLE "DBS_P2P"."KW_PAYMENT_IMAGEE_TEST"(IMAGE_KEY INTEGER PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY ( START WITH +1 INCREMENT BY +1 MINVALUE +1 MAXVALUE +2147483647 NO CYCLE CACHE 20 NO ORDER),REQUEST_ID INTEGER,IMAGE_CONTENT CLOB(5120000),FOREIGN KEY(REQUEST_ID) REFERENCES KW_PAYMENT_LINK_MASTER_TEST(REQUEST_ID))
CREATE TABLE "DBS_P2P"."KW_PAYMENT_IMAGEE_TEST"(IMAGE_KEY INTEGER PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY ( START WITH +1 INCREMENT BY +1 MINVALUE +1 MAXVALUE +2147483647 NO CYCLE CACHE 20 NO ORDER),REQUEST_ID INTEGER,IMAGE_CONTENT CLOB(5120000),FOREIGN KEY(REQUEST_ID) REFERENCES KW_PAYMENT_LINK_MASTER_TEST(REQUEST_ID))
<hibernate-mapping>
<class name="xyz" table="KW_PAYMENT_LINK_MASTER_TEST" catalog="xyz">
<id name="requestId" type="int">
<column name="REQUEST_ID"/>
<generator class="identity" />
</id>
<property name="referenceWalletId" type="string">
<column name="REFERENCE_ID"/>
</property>
</class>
<hibernate-mapping>
<class name="com.kony.p2p.bo.KwPaymentImagetest" table="KW_PAYMENT_IMAGEE_TEST" catalog="DBS_P2P">
<id name="imageKey" type="int">
<column name="IMAGE_KEY" />
<generator class="identity" />
</id>
<many-to-one name="KwPaymentLinkMastertest" class="com.kony.p2p.bo.KwPaymentLinkMastertest" fetch="select" lazy="false">
<column name="REQUEST_ID" not-null="false" />
</many-to-one>
<property name="imageContent" type="string">
<column name="IMAGE_CONTENT" not-null="false" />
</property>
</class>
<filter-def name="myFilter">
Im able to insert but not able to retrieve the result .
session.createCriteria(KwPaymentLinkMastertest.class).add(Restrictions.eq("requestId", Integer.parseInt(transactionReferenceNumber) )).uniqueResult();
KwPaymentImagetest image = (KwPaymentImagetest) session.createCriteria(KwPaymentImagetest.class).add(Restrictions.eq("kwPaymentLinkMastertest", kwPaymentLinkMastertest)).uniqueResult();
Getting the following error
org.hibernate.QueryException: could not resolve property: kwPaymentLinkMastertest of: com.kony.p2p.bo.KwPaymentImagetest
Please help fix
I think you have typing mistake here.
<many-to-one name="KwPaymentLinkMastertest" with K is upper case
while Restrictions.eq("kwPaymentLinkMastertest" with k is lower case.
Ya,
You are right .
The problem was with small letter and capital letter , this helped to fix my problem.
Thanks.
Related
I am trying to load CSV file into SQLserver table using Liquibase change log set.
When saved XLSX file as CSV file, column containing comma saved in double quotes (please see 3rd value below), this is fine as per standards but liquibase is ignoring double quotes and considering comma inside the double-quotes.
13,OV,"Diabetes outpatient self-management training services individual,per 30 minutes",77.82,1,0,1/4/2016,,G0108
Error messgae from command line terminal:
CSV file v2.1/r21/TestData20212021.csv Line 21 has 10 values defined, Header has 9. Numbers MUST be equal (check for unquoted string with embedded commas)
<changeSet author="sprint-developer" id="sprint1-09">
<loadData
file="v2.1/r21/TestData2021.csv"
tableName = "tbl_Votes" encoding="UTF-8" >
<column header="VcenarioID" name="VcenarioID" type="numeric"/>
<column header="venefitCode" name="venefitCode" type="string"/>
<column header="KostDescription" name="KostDescription" type="string"/>
<column header="Kost" name="Kost" type="NUMERIC"/>
<column header="OcKurrences" name="OKcurrences" type="numeric"/>
<column header="KostIsPerIncident" name="KostIsPerIncident" type="boolean"/>
<column header="KostDate" name="KostDate" type="date"/>
<column header="VundleId" name="VundleId" type="NUMERIC"/>
<column header="VillingCode" name="VillingCode" type="string"/>
</loadData>
<rollback>Delete from tbl_Votes where VcenarioID=13 </rollback>
</changeSet>
Try adding quotchar='"' to your changeSet. This should tell liqbuiase to treat everything inside "" as one single value.
Check out loadData docs.
So your changeSet could look like this:
<changeSet author="sprint-developer" id="sprint1-09">
<loadData
file="v2.1/r21/TestData2021.csv"
tableName = "tbl_Votes" encoding="UTF-8" quotchar='"'>
<column header="VcenarioID" name="VcenarioID" type="numeric"/>
<column header="venefitCode" name="venefitCode" type="string"/>
<column header="KostDescription" name="KostDescription" type="string"/>
<column header="Kost" name="Kost" type="NUMERIC"/>
<column header="OcKurrences" name="OKcurrences" type="numeric"/>
<column header="KostIsPerIncident" name="KostIsPerIncident" type="boolean"/>
<column header="KostDate" name="KostDate" type="date"/>
<column header="VundleId" name="VundleId" type="NUMERIC"/>
<column header="VillingCode" name="VillingCode" type="string"/>
</loadData>
<rollback>Delete from tbl_Votes where VcenarioID=13 </rollback>
</changeSet>
I have an interesting use-case where I'd like Hibernate to manage multiple one-to-many relationships to the same entity type.
For example: BookShelf fictionBooks relationship to Book(s), but also BookShelf nonFictionBooks mapped to Book(s). The Hibernate mapping would look something like this:
<class name="com.example.BookStore" table="BOOK_SHELF">
<id name="id" type="long" column="bookShelfId">
<generator class="native" />
</id>
<set name="fictionBooks" table="SHELF_BOOK" cascade="all-delete-orphan" lazy="false">
<key column="bookShelfId" />
<one-to-many class="com.example.Book" />
</set>
<set name="nonFictionBooks" table="SHELF_BOOK" cascade="all-delete-orphan" lazy="false">
<key column="bookShelfId" />
<one-to-many class="com.example.Book" />
</set>
</class>
<class name="com.example.Book" table="SHELF_BOOK">
<id name="id" type="long" column="shelfBookId">
<generator class="native" />
</id>
<property name="name" not-null="true" unique="true"/>
</class>
Is there a way for the relationship owner BookShelf to specify some discriminator value which could be used to differentiate between Fiction and Non-Fiction books? If possible, the discriminator would be stored as an additional column in SHELF_BOOK table and Hibernate would automatically filter on that.
Is there a way to do this without resorting to either a many-to-many association or extending the Book entity with a Table per class strategy?
Ideally you should have a "type" or "flag" column in SHELF_BOOK table indicating the book is fiction or non-fiction.
Suppose you have added this "type" column, then I think you could specify a filter statement in the set:
<set name="fictionBooks" table="SHELF_BOOK" cascade="all-delete-orphan" lazy="false">
<filter name="myfilter" condition=":type = 'FICTION'"/>
<key column="bookShelfId" />
<one-to-many class="com.example.Book" />
</set>
You can refer to http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#objectstate-filters
From what you posted, I can say that in order to achieve what you wanted you need to modify your relationship owner BookShelf to only store reference to Book and add the property, say bookType, to Book entity.
<class name="com.example.BookStore" table="BOOK_SHELF">
<id name="id" type="long" column="bookShelfId">
<generator class="native" />
</id>
<set name="books" table="SHELF_BOOK" cascade="all-delete-orphan" lazy="false">
<key column="bookShelfId" />
<one-to-many class="com.example.Book" />
</set>
</class>
<class name="com.example.Book" table="SHELF_BOOK">
<id name="id" type="long" column="shelfBookId">
<generator class="native" />
</id>
<property name="name" not-null="true" unique="true"/>
<property name="bookType" not-null="true"/>
</class>
There is no other(except ManytoMany) way by which you can find out the type of book by looking into BookShelf entity. You can also use Single Table Strategy which will automatically add the discriminator to the inserted values but in order to do that you need to create two separate classes for FictionalBook and NonFictionalBook .
I receive the following error when calling insert stored procedure in Hibernate while working with MySQL db:
Hibernate:
{ call InsertPayment(?, ?) }
sie 28, 2013 10:17:19 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: S1009
sie 28, 2013 10:17:19 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Parameter index out of range (3 > number of parameters, which is 2).
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert: [model_mapping_xml.TPayment]
Stored procedure definition in MySQL db:
CREATE PROCEDURE InsertPayment(
IN pIdAnother INT,
IN pAmount DECIMAL(19,4)
)
BEGIN
...
END
TPayment.hbm.xml file contains:
<sql-insert callable="true" check="none">
{ call InsertPayment(?, ?) }
</sql-insert>
Implicit call of the stored procedure:
// calling the stored procedure to add payment
TPayment newp = new TPayment();
newp.setAnother((TAnother) session.load(TAnother.class, 1));
newp.setAmount(BigDecimal.valueOf(20));
session.save(newp);
Why does it say "3 > number of parameters" where everywhere there are 2 parameters for this procedure?
(I can call deletePayment and modifyPayment stored procedures in similar way and they work fine...).
TPayment mapping:
<hibernate-mapping>
<class name="model_mapping_xml.TPayment" table="TPayment" catalog="DB">
<id name="idPayment" type="java.lang.Integer">
<column name="IdPayment" />
<generator class="identity" />
</id>
<version name="rowvers" type="timestamp" generated="always">
<column name="Rowvers" length="19" not-null="true" />
</version>
<many-to-one name="another" class="model_mapping_xml.TAnother" fetch="select">
<column name="IdAnother" not-null="true" />
</many-to-one>
<property name="amount" type="big_decimal">
<column name="Amount" scale="4" not-null="true" />
</property>
<property name="date1" type="timestamp">
<column name="Date1" length="19" not-null="false" />
</property>
<sql-insert callable="true" check="none">
{ call InsertPayment(?, ?) }
</sql-insert>
<sql-update callable="true" check="none">
{ call ModifyPayment(?, ?, ?, ?, ?) }
</sql-update>
<sql-delete callable="true" check="none">
{ call DeletePayment(?, ?) }
</sql-delete>
</class>
</hibernate-mapping>
TAnother mapping:
<hibernate-mapping>
<class name="model_mapping_xml.TAnother" table="TAnother" catalog="DB">
<id name="idAnother" type="java.lang.Integer">
<column name="IdAnother" />
<generator class="identity" />
</id>
<property name="dateBegin" type="date">
<column name="DateBegin" length="10" not-null="true" />
</property>
<property name="dateEnd" type="date">
<column name="DateEnd" length="10" />
</property>
<property name="rowvers" type="timestamp">
<column name="Rowvers" length="19" not-null="true" />
</property>
<set name="payment" table="TPayment"
inverse="true" lazy="true" fetch="select">
<key>
<column name="IdAnother" not-null="true" />
</key>
<one-to-many class="model_mapping_xml.TPayment" />
</set>
</class>
</hibernate-mapping>
I am developing a web based application using spring-hibernate combination with Mysql as a database. I have observed 1 problem with hibernate mapping that it doesn't allow me to set null, when type is timestamp. Here is code snippet for better understanding
Here my agenda is - I want to allow user to enter null value for endTime, not for stTime.
schedule.htm.xml
<id
name="id"
type="long"
column="test_run_schedule_id"
>
<generator class="increment" />
</id>
<property
name="testName"
type="java.lang.String"
column="test_run_name"
not-null="true"
length="45"
/>
<property
name="operation"
type="java.lang.String"
column="operation_included"
not-null="true"
length="500"
/>
<property
name="stTime"
type="java.util.Date"
column="start_time"
not-null="true"
length="19"
/>
<property
name="endTime"
type="java.util.Date"
column="end_time"
not-null="false"
length="19"
/>
When I looked into Mysql database, it showing me Columns start_time [timestamp, NOTNULL], as well as end_time [timestamp, NOTNULL] instead of end_time[timestamp, NULL].
So when I insert value, end_time is always taken as CURRENT_TIMESTAMP by default.
How do I create a NULLABLE end_time column?
I am using Spring HibernateTemplate, OpenSessionInViewFilter(actually I extended this class and created my own to switch to FLUSH.AUTO Mode) and Mysql for implementing hibernate many-to-many association. However when I save an object, corresponding many-to-many table's values are not inserted. Does anybody can help me? Thank you.
here is the mapping xml
<hibernate-mapping>
<class name="com.intelli.epub.domain.Content" table="CONTENT">
<id name="id" type="java.lang.Long">
<column name="ID" />
<generator class="native" />
</id>
<property name="title" type="java.lang.String">
<column name="TITLE" />
</property>
<property name="text" type="java.lang.String">
<column name="TEXT" />
</property>
<many-to-one name="writer" class="com.intelli.epub.domain.User" fetch="join">
<column name="WRITER" />
</many-to-one>
<property name="createdDate" type="java.util.Date">
<column name="CREATEDDATE" />
</property>
<set name="menus" table="MENU_CONTENT" cascade="all">
<key column="CONTENT_ID"></key>
<many-to-many column="MENU_ID" class="com.intelli.epub.domain.Menu"/>
</set>
</class>
</hibernate-mapping>
another one:
<hibernate-mapping>
<class name="com.intelli.epub.domain.Menu" table="MENU">
<id name="id" type="java.lang.Long">
<column name="ID" />
<generator class="native" />
</id>
<property name="text" type="java.lang.String">
<column name="TEXT" />
</property>
<set name="contents" table="MENU_CONTENT" inverse="true">
<key column="MENU_ID"></key>
<many-to-many column="CONTENT_ID" class="com.intelli.epub.domain.Content"/>
</set>
</class>
and when saving like this:
Content content = new Content();
content.setCreatedDate(new Date());
content.setWriter(some user here);
content.setText("some text here");
Menu menu1 = new Menu("menu1");
Menu menu2 = new Menu("menu2");
Set<Menu> menus = new HashSet();
menus.add(menu1);
menus.add(menu2);
content.setMenus(menus);
contentDao.saveOrUpdate(content);
Now menu1 and menu2 would be saved in the MENU table, However nothing happens to MENU_CONTENT table; MENU_CONTENT table doesn't have a primary key field, instead MENU_ID and CONTENT_ID are primary key together. I don't know if it's the problem. Please help me. Thank you.
I found a solution. Instead of using Spring HibernateTemplate. I wrapped it in regular session and transaction like this.
Session session = contentDao.getHibernateTemplate().getSessionFactory().getCurrentSession();
transaction = session.beginTransaction();
Content content = new Content();
content.setCreatedDate(new Date());
content.setWriter(some user here);
content.setText("some text here");
Menu menu1 = new Menu("menu1");
Menu menu2 = new Menu("menu2");
Set<Menu> menus = new HashSet();
menus.add(menu1);
menus.add(menu2);
content.setMenus(menus);
session.save(content);
transaction.commit();
session.close();
And here is my session filter which inherited from OpenSessionInViewFilter
public class SessionFilter extends OpenSessionInViewFilter {
protected Session getSession(SessionFactory sessionFactory)
throws DataAccessResourceFailureException {
Session session = super.getSession(sessionFactory);
session.setFlushMode(FlushMode.AUTO);
return session;
}
}
Does anybody know a way to handle this without bothering to write session management myself?