newbie: problem persisting multiple objects
henderson_mk Oct 14, 2005 4:28 PMHi folks,
Been playing around with seam for the past day or so and am liking it, but have run into some diffs...
I've created a page to register a property and then the registerPropertyAction is like this:
@Scope(EVENT)
@Name("registerProperty")
public class RegisterPropertyAction
{
/**
* Register a property
*/
@IfInvalid(outcome=REDISPLAY)
public String register()
{
log.info("registering property");
List existing = propertyDatabase.createQuery(
"select streetName1 from Address where streetName1=:address")
.setParameter("address", address.getStreetName1())
.list();
String result = null;
if (existing.size() == 0)
{
property.setAddress(address);
log.info("property=" + property);
propertyDatabase.persist(property);
propertyDatabase.flush();
result = "success";
}
else
{
facesContext.addMessage(null, new FacesMessage("Property already exists"));
result = null;
}
log.info("registered user");
return result;
}
/**
* Is the property object to register.
*/
@In @Valid
private Property property;
/**
* Is the addres object for the property.
*/
@In @Valid
private Address address;
/**
* Is the property database.
*/
@In(create=true)
private Session propertyDatabase;
/**
* Is the JSF Context.
*/
@In
private FacesContext facesContext;
what I'm finding though is I can call it once... but then if I try to call it again I'm getting:
21:28:07,859 INFO [RegisterPropertyAction] registering property 21:28:07,875 INFO [STDOUT] Hibernate: select address0_.streetName1 as col_0_0_ from Address address0_ where address0_.streetName1=? 21:28:07,875 INFO [RegisterPropertyAction] property=org.mhenderson.turnaround.d omain.Property@132e6fd[id=0,address=org.mhenderson.turnaround.domain.Address@db2 a34[id=0,streetName1=dsfds,streetName2=sdfds,streetName3=fdsfds,city=sdfds,count y=,country=,postCode=],bathroomCount=0,bedroomCount=0,receptionCount=0] 21:28:07,875 INFO [STDOUT] Hibernate: insert into Property (address_id, bedroom Count, receptionCount, bathroomCount, id) values (?, ?, ?, ?, null) 21:28:07,875 INFO [STDOUT] Hibernate: call identity() 21:28:07,875 INFO [STDOUT] Hibernate: insert into Address (country, city, count y, streetName1, streetName2, streetName3, postCode, id) values (?, ?, ?, ?, ?, ? , ?, ?) 21:28:07,875 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: null 21:28:07,875 ERROR [JDBCExceptionReporter] failed batch 21:28:07,875 ERROR [AbstractFlushingEventListener] Could not synchronize databas e state with session org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch updat e at org.hibernate.exception.SQLStateConverter.handledNonSpecificException (SQLStateConverter.java:91) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.j ava:79) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelp er.java:43) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java: 200) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutio ns(AbstractFlushingEventListener.java:296) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlus hEventListener.java:27)
any help would really *really* be appreciated...
Thanks
Marty