Hola,
I'm working with a table which primary key is a Serial data type.
How can I map a serial field in XMLPortletFactory?.
My problem came when I try to insert a new value in a table with populated data, because the generated "PK Id" cause a ConstraintViolationException ( org.hibernate.exception.ConstraintViolationException)
Details:
- Create a "cities" portlet
- Populate cities table with (624) values from a insert script:
1insert into exampleportlet_cities(citid, citdesc, citdescalternative, citcodpost, prvid, companyid, groupid, userid)
2select cit_id, cit_desc, cit_desc_alternative, cit_codpost, prv_id, 10131, 13036, 10168 from cities;
- install the new "Cities portlet" in a Liferay page (see attach image)
- Create new city
- ERROR:
115:41:27,281 ERROR [jsp:154] java.sql.BatchUpdateException: Batch entry 0 insert into architectsmaintenance_cities (companyId, groupId, userId, citDesc, citDescAlternative, citCodp
2ost, prvId, citId) values ('10131', '13036', '10168', 'Boston', 'Boston USA', '007', '11', '[b]4[/b]') was aborted. Call getNextException to see the cause.
3 at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2598)
4 at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1836)
5 at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:407)
6 at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2737)
7 at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
8 at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
9 at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
10 at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
11 at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:179)
12 at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
13 at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
14 at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
15 at com.liferay.portal.dao.orm.hibernate.SessionImpl.flush(SessionImpl.java:108)
16 at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:54)
17 at com.liferay.portal.service.persistence.BatchSessionImpl.update(BatchSessionImpl.java:66)
18 at com.liferay.portal.service.persistence.BatchSessionUtil.update(BatchSessionUtil.java:43)
19 at org.xmlportletfactory.portal.coavnbiz.service.persistence.citiesPersistenceImpl.updateImpl(citiesPersistenceImpl.java:285)
20 at org.xmlportletfactory.portal.coavnbiz.service.persistence.citiesPersistenceImpl.updateImpl(citiesPersistenceImpl.java:71)
21 at com.liferay.portal.service.persistence.impl.BasePersistenceImpl.update(BasePersistenceImpl.java:255)
22 at com.liferay.portal.dao.shard.ShardAdvice.invokePersistence(ShardAdvice.java:205)
In the above exception you can see an INSERT with citId=4 and in the table exists Ids from 1 to 624.
This is part of the XML description file where I map
citId as long:
1 <fileDef>
2 <name>cities</name>
3 <fields>
4 <field>
5 <name>citId</name>
6 <title>Id</title>
7 <type>
8 <long>
9 <length>10</length>
10 <signed>false</signed>
11 <nullable>false</nullable>
12 </long>
13 </type>
14 <showFieldInView>false</showFieldInView>
15 </field>
Saludos,
David.