you have to add a @CommitAfter in the method where update takes place, or do a commit, there is a change in default action from commit to abort, it's in the doc.
bernatowicz wrote: > > Hello. I have 2 entities with a parent-child relationship. Client is the > parent, and Project is the child. In 5.0.11 each Project entity is > written to the (mysql) DB correctly with its client's ID, but in 5.0.12+ > each Project's client_id is zero. > > I applied the following source code changes to upgrade from 5.0.11: > > * Changed import statements to reflect the renamed tapestry5 package. > In AppModule.java: > * Changed TapestryConstants.SUPPORTED_LOCALES_SYMBOL to > SymbolConstants.SUPPORTED_LOCALES > * Changed TapestryConstants.PRODUCTION_MODE_SYMBOL to > SymbolConstants.PRODUCTION_MODE > > No other changes were made. I then changed the Tapestry version in > pom.xml and fired it up with mvn jetty:run. > > Are there additional code or config changes that are required to keep this > functionality working in 5.0.12+? > > Many thanks for your help! > Jim > > ------------------------------ HbAction.java: > > package net.bernatowicz.tapestry.pages; > > import java.util.List; > > import org.apache.tapestry5.ioc.annotations.Inject; > import org.hibernate.Session; > > import java.util.Date; > import java.util.ArrayList; > import java.text.SimpleDateFormat; > import java.text.ParseException; > > import net.bernatowicz.tapestry.entities.Hello; > import net.bernatowicz.tapestry.entities.Client; > import net.bernatowicz.tapestry.entities.YesNo; > import net.bernatowicz.tapestry.entities.Project; > > public class HbAction { > > @Inject > private Session _session; > private Hello current; > > public void onAction() { > Hello h = new Hello(); > h.setCreatedOn(new Date()); > h.setMessage("Hello"); > _session.save(h); > ArrayList clientProjects = new ArrayList(); > > // Client is the parent: > SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); > Client c = new Client(); > c.setActive(YesNo.YES); > c.setName("InfiNet Marketing Group, Inc."); > _session.save(c); > > // Project (1) is a child: > Project p = new Project(); > p.setActive(YesNo.YES); > p.setClient(c); > try { > p.setDueDate(sdf.parse("04/01/2008")); > } catch (ParseException e) { > e.printStackTrace(); > } > p.setName("Redesign Woodlyn Sales Website"); > p.setSortKey(9); > _session.save(p); > > clientProjects.add(p); > > // Project (2) is another child: > p = new Project(); > p.setActive(YesNo.YES); > p.setClient(c); > try { > p.setDueDate(sdf.parse("4/15/08")); > } catch (ParseException e) { > e.printStackTrace(); > } > p.setName("Do Taxes"); > p.setSortKey(2); > clientProjects.add(p); > > _session.save(p); > > c.setProjects(clientProjects); > _session.save(c); > } > > public List getList() { > return _session.createCriteria(Hello.class).list(); > } > > public Hello getCurrent() { > return current; > } > > public void setCurrent(Hello current) { > this.current = current; > } > } > > ------------------------------ Client.java: > > package net.bernatowicz.tapestry.entities; > > import javax.persistence.*; > import java.util.*; > import java.io.Serializable; > > @Entity > @Table(name = "client") > public class Client implements Serializable { > public Client() { > created = new Date(); > } > @Id > @GeneratedValue > @Column(name = "client_id") > private long id; > > @Column(name = "name", length = 50) > private String name; > > @Column(name = "active") > private YesNo active; > > @Column(name = "created") > private Date created; > > @Column(name = "updated") > private Date updated; > > @OneToMany( > targetEntity = Project.class, > cascade = {CascadeType.ALL}, > fetch = FetchType.EAGER > ) > @JoinColumn(name = "client_id") > @org.hibernate.annotations.Cascade( > value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN > ) > @org.hibernate.annotations.IndexColumn(name = "sort_key") > private List projects = new ArrayList(); > > public long getId() { > return id; > } > > public String getName() { > return name; > } > > public void setName(String name) { > this.name = name; > updated = new Date(); > } > > public YesNo getActive() { > return active; > } > > public void setActive(YesNo active) { > this.active = active; > updated = new Date(); > } > > public Date getCreated() { > return created; > } > > public void setCreated(Date created) { > this.created = created; > updated = new Date(); > } > > public Date getUpdated() { > return updated; > } > > public void setUpdated(Date updated) { > this.updated = updated; > } > > public List getProjects() { > return projects; > } > > public void setProjects(List projects) { > this.projects = projects; > } > > public long getId2() { > return id; > } > > } > > ------------------------------ Project.java: > > package net.bernatowicz.tapestry.entities; > > import javax.persistence.*; > import java.util.Date; > import java.io.Serializable; > > @Entity > @Table(name = "project") > public class Project implements Serializable { > public Project() { > created = new Date(); > } > > @Id > @GeneratedValue > @Column(name = "project_id") > private long id; > > @Column(name = "name", length = 50) > private String name; > > @Column(name = "due_date") > private Date dueDate; > > @Column(name = "sort_key") > private int sortKey; > > @Column(name = "active") > private YesNo active; > > @Column(name = "created") > private Date created; > > @Column(name = "updated") > private Date updated; > > @ManyToOne(targetEntity = Client.class) > @JoinColumn(name = "client_id", nullable = false, updatable = false, > insertable = false) > private Client client; > > public long getId() { > return id; > } > > public long getId2() { > return id; > } > > public String getName() { > return name; > } > > public void setName(String name) { > this.name = name; > updated = new Date(); > } > > public Date getDueDate() { > return dueDate; > } > > public void setDueDate(Date dueDate) { > this.dueDate = dueDate; > } > > public int getSortKey() { > return sortKey; > } > > public void setSortKey(int sortKey) { > this.sortKey = sortKey; > } > > public YesNo getActive() { > return active; > } > > public void setActive(YesNo active) { > this.active = active; > } > > public Client getClient() { > return client; > } > > public void setClient(Client client) { > this.client = client; > } > > public Date getCreated() { > return created; > } > > public void setCreated(Date created) { > this.created = created; > updated = new Date(); > } > > public Date getUpdated() { > return updated; > } > > public void setUpdated(Date updated) { > this.updated = updated; > } > } > > ------------------------------ pom.xml: > > <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 > http://maven.apache.org/maven-v4_0_0.xsd" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns="http://maven.apache.org/POM/4.0.0"> > <modelVersion>4.0.0</modelVersion> > <groupId>net.bernatowicz</groupId> > <artifactId>demonstrosity</artifactId> > <version>1.0.0-SNAPSHOT</version> > <packaging>war</packaging> > <name>Tapestry 5 Demonstrosity</name> > <dependencies> > <dependency> > <groupId>org.apache.tapestry</groupId> > <artifactId>tapestry-core</artifactId> > <version>${tapestry-release-version}</version> > </dependency> > > <!-- for hibernate --> > <dependency> > <groupId>org.apache.tapestry</groupId> > <artifactId>tapestry-hibernate</artifactId> > <version>${tapestry-release-version}</version> > </dependency> > <dependency> > <groupId>org.hibernate</groupId> > <artifactId>hibernate</artifactId> > <version>3.2.2.ga</version> > </dependency> > <dependency> > <groupId>c3p0</groupId> > <artifactId>c3p0</artifactId> > <version>0.9.0</version> > </dependency> > <dependency> > <groupId>geronimo-spec</groupId> > <artifactId>geronimo-spec-jta</artifactId> > <version>1.0-M1</version> > <scope>test</scope> > </dependency> > <dependency> > <groupId>org.hibernate</groupId> > <artifactId>hibernate-annotations</artifactId> > <version>3.2.1.ga</version> > </dependency> > <dependency> > <groupId>mysql</groupId> > <artifactId>mysql-connector-java</artifactId> > <version>3.1.12</version> > </dependency> > <!-- for hibernate --> > > <dependency> > <groupId>jasperreports</groupId> > <artifactId>jasperreports</artifactId> > <version>3.0.0</version> > </dependency> > > <dependency> > <groupId>jexcelapi</groupId> > <artifactId>jxl</artifactId> > <version>2.6</version> > </dependency> > > <dependency> > <groupId>com.lowagie</groupId> > <artifactId>itext</artifactId> > <version>2.0.8</version> > </dependency> > > <!-- can we use the dependency of iText from jasperreports? YES!! > <dependency> > <groupId>jfree</groupId> > <artifactId>jfreechart</artifactId> > <version>1.0.9</version> > </dependency> > --> > > <dependency> > <groupId>opensymphony</groupId> > <artifactId>sitemesh</artifactId> > <version>2.3</version> > </dependency> > > <!-- A dependency on either JUnit or TestNG is required, or the > surefire plugin (which runs the tests) > will fail, preventing Maven from packaging the WAR. Tapestry includes a > large number > of testing facilities designed for use with TestNG (http://testng.org/), > so it's recommended. --> > <dependency> > <groupId>org.testng</groupId> > <artifactId>testng</artifactId> > <version>5.1</version> > <classifier>jdk15</classifier> > <scope>test</scope> > </dependency> > > </dependencies> > <build> > <finalName>demonstrosity</finalName> > <plugins> > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-compiler-plugin</artifactId> > <configuration> > <source>1.5</source> > <target>1.5</target> > <optimize>true</optimize> > </configuration> > </plugin> > > <!-- Run the application using "mvn jetty:run" --> > <plugin> > <groupId>org.mortbay.jetty</groupId> > <artifactId>maven-jetty-plugin</artifactId> > <configuration> > <!-- Log to the console. --> > <requestLog > implementation="org.mortbay.jetty.NCSARequestLog"> > <!-- This doesn't do anything for Jetty, but is a > workaround for a Maven bug > that prevents the requestLog from being set. > --> > <append>true</append> > </requestLog> > </configuration> > </plugin> > > <!-- This changes the WAR file packaging so that what would > normally go into WEB-INF/classes > is instead packaged as WEB-INF/lib/tapps.jar. This is > necessary for Tapestry > to be able to search for page and component classes at > startup. Only > certain application servers require this configuration, > please see the documentation > at the Tapestry 5 project page > (http://tapestry.apache.org/tapestry5/). --> > > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-war-plugin</artifactId> > <configuration> > <archiveClasses>true</archiveClasses> > </configuration> > </plugin> > </plugins> > > </build> > > <reporting> > > <!-- Adds a report detailing the components, mixins and base > classes defined by this module. --> > <plugins> > <plugin> > <groupId>org.apache.tapestry</groupId> > <artifactId>tapestry-component-report</artifactId> > <version>${tapestry-release-version}</version> > <configuration> > <rootPackage>net.bernatowicz.tapestry</rootPackage> > </configuration> > </plugin> > </plugins> > </reporting> > > <repositories> > <!-- This can be commented out when the tapestry-release-version > is a not a snapshot. > The non-snapshot Tapestry artifacts are distributed through the central > repository at ibiblio. --> > > <repository> > <id>tapestry-snapshots</id> > > <url>http://tapestry.formos.com/maven-snapshot-repository/</url> > </repository> > > <repository> > <id>codehaus.snapshots</id> > <url>http://snapshots.repository.codehaus.org</url> > </repository> > <!-- For access to the selenium JARs. --> > <repository> > <id>openqa</id> > <name>OpenQA Maven Repository</name> > <url>http://maven.openqa.org/</url> > </repository> > </repositories> > <pluginRepositories> > > <!-- As above, this can be commented out when access to the > snapshot version > of a Tapestry Maven plugin is not required. --> > <pluginRepository> > <id>tapestry-snapshots</id> > > <url>http://tapestry.formos.com/maven-snapshot-repository/</url> > </pluginRepository> > > </pluginRepositories> > > <properties> > <tapestry-release-version>5.0.13</tapestry-release-version> > </properties> > </project> > > -- View this message in context: http://www.nabble.com/T5%3A-Hibernate-OneToMany%3A-Works-in-5.0.11%2C-Fails-in-12%2C-13%2C-14-SNAPSHOT-tp18884360p18884427.html Sent from the Tapestry - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]