I have noticed that this happens only when you extend GenericManagerImpl
(in the impl) and GenericManager in you interface. If you do not extend
these classes and interfaces it works alright. Hope this helps people
to get closer to the bug?
My implementation which works.
==============applicationConfig.xml==================
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="personDao"
class="org.appfuse.dao.hibernate.GenericDaoHibernate">
<constructor-arg value="org.appfuse.tutorial.model.Person"/>
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="contactDetailManager"
class="org.appfuse.service.impl.GenericManagerImpl">
<constructor-arg>
<bean class="org.appfuse.dao.hibernate.GenericDaoHibernate"
autowire="byType">
<constructor-arg
value="org.appfuse.tutorial.model.ContactDetail"/>
</bean>
</constructor-arg>
</bean>
<bean id="personManager"
class="org.appfuse.tutorial.service.impl.PersonManagerImpl">
<property name="dao" ref="personDao" />
<property name="contactDetailManager" ref="contactDetailManager" />
</bean>
<bean id="personAction"
class="org.appfuse.tutorial.webapp.action.PersonAction" scope="prototype">
<property name="personManager" ref="personManager"/>
</bean>
</beans>
==================================================================
====================PersonManagerImpl================================
package org.appfuse.tutorial.service.impl;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.appfuse.dao.GenericDao;
import org.appfuse.service.GenericManager;
import org.appfuse.tutorial.model.ContactDetail;
import org.appfuse.tutorial.model.Person;
import org.appfuse.tutorial.service.PersonManager;
public class PersonManagerImpl implements PersonManager {
GenericDao<Person, Long> dao;
GenericManager<ContactDetail, Long> contactDetailManager;
protected final Log log = LogFactory.getLog(getClass());
public PersonManagerImpl() {
}
public void setDao(GenericDao<Person, Long> dao){
this.dao = dao;
}
public void setContactDetailManager(GenericManager<ContactDetail,
Long> contactDetailManager){
this.contactDetailManager = contactDetailManager;
}
public void save(Person person){
log.debug("Started Save Person");
dao.save(person);
log.debug("Saved Person");
log.debug("Starting Iterator of Contact Details");
for (Iterator iter = person.getContactDetails().iterator();
iter.hasNext();) {
ContactDetail contactDetail = (ContactDetail) iter.next();
contactDetail.setPerson(person);
log.debug("Finished Setting Person in Contact Details going
to Save Contact Details");
contactDetailManager.save(contactDetail);
log.debug("Saved Contact Details");
}
dao.save(person);
}
public void test() {
log.debug("Test Called");
}
public Person getPerson(Long id) {
return dao.get(id);
}
public List getPeople() {
return dao.getAll();
}
public void remove(Long id) {
dao.remove(id);
}
}
=======================================================
===================PersonManager=========================
package org.appfuse.tutorial.service;
import java.util.List;
import org.appfuse.tutorial.model.Person;
public interface PersonManager {
public void save(Person person);
public List getPeople();
public Person getPerson(Long id);
public void remove(Long id);
public void test();
}
===============================================
================Person.java=======================
package org.appfuse.tutorial.model;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import org.appfuse.model.BaseObject;
import org.appfuse.tutorial.util.IdGenerator;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
@Entity
public class Person extends BaseObject {
/**
*
*/
private static final long serialVersionUID = 1L;
Long id;
String firstName;
String lastName;
String uuid = IdGenerator.getUuid();
List<ContactDetail> contactDetails;
@Column(name="first_name")
public String getFirstName() {
return firstName;
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public Long getId() {
return id;
}
@Column(name="last_name")
public String getLastName() {
return lastName;
}
@Column(name="uuid")
public String getUuid() {
return uuid;
}
@OneToMany(mappedBy="person")
public List<ContactDetail> getContactDetails() {
if(contactDetails == null)
contactDetails = new ArrayList();
return contactDetails;
}
public void setUuid(String uuid) {
if
(uuid.matches("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}")){
this.uuid = uuid;
}
}
public void setContactDetails(List<ContactDetail> contactDetails) {
for (Iterator iter = contactDetails.iterator(); iter.hasNext();) {
ContactDetail contactDetail = (ContactDetail) iter.next();
contactDetail.setPerson(this);
}
this.contactDetails = contactDetails;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setId(Long id) {
this.id = id;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* @see java.lang.Object#equals(Object)
*/
public boolean equals(final Object object) {
if (object == this) {
return true;
}
if (!(object instanceof Person)) {
return false;
}
Person rhs = (Person) object;
return new EqualsBuilder().append(this.uuid, rhs.uuid).isEquals();
}
/**
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return new HashCodeBuilder(-1470813203, 697538089)
.append(this.uuid)
.toHashCode();
}
/**
* @see java.lang.Object#toString()
*/
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("lastName", this.lastName).append("id", this.id)
.append("uuid", this.uuid).append("firstName",
this.firstName)
.toString();
}
}
======================================================
==================ContactDetail.java=======================
package org.appfuse.tutorial.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.appfuse.model.BaseObject;
import org.appfuse.tutorial.util.IdGenerator;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
@Entity
public class ContactDetail extends BaseObject {
private Long id;
private String uuid = IdGenerator.getUuid();
private String street;
private String city;
private Person person;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
public String getCity() {
return city;
}
@ManyToOne
@JoinColumn(name = "person_id")
public Person getPerson() {
return person;
}
public String getStreet() {
return street;
}
public String getUuid() {
return uuid;
}
public void setCity(String city) {
this.city = city;
}
public void setId(Long id) {
this.id = id;
}
public void setPerson(Person person) {
this.person = person;
}
public void setStreet(String street) {
this.street = street;
}
public void setUuid(String uuid) {
if (uuid
.matches("[0-9a-fA-F]{8}-" +
"[0-9a-fA-F]{4}-" +
"[0-9a-fA-F]{4}-" +
"[0-9a-fA-F]{4}-" +
"[0-9a-fA-F]{12}")) {
this.uuid = uuid;
}
}
/**
* @see java.lang.Object#toString()
*/
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", this.id).append("street", this.street).append(
"person", this.person).append("uuid", this.uuid)
.append("city", this.city).toString();
}
/**
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return new HashCodeBuilder(-2089027693,
-1069532863).append(this.uuid)
.toHashCode();
}
/**
* @see java.lang.Object#equals(Object)
*/
public boolean equals(final Object object) {
if (object == this) {
return true;
}
if (!(object instanceof ContactDetail)) {
return false;
}
ContactDetail rhs = (ContactDetail) object;
return new EqualsBuilder().append(this.uuid, rhs.uuid).isEquals();
}
}
=====================================================
maskkkk wrote:
Hello Appfuse crew,
Initially upon following the tutorial in which a Person object was created
and edited, I could edit the various person objects in the database.
However now that I have re-checked the project out I recieve the following
error when editing/creating and saving (only) Person objects:
Data Access Failure
Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn
your Session into FlushMode.AUTO or remove 'readOnly' marker from
transaction definition
What could be causing this? (I'm new to Hibernate, it looks like maybe a
Hibernate error, or possibily something to do with the MySQL database.) Oh
and By the way I can edit user profiles without any trouble.
Thank you,
(for making Appfuse, and helping with my questions)
Andrew J. Leer
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]