...
What happened is that we haven't told Tapestry what to do after the form is succesfully successfully submitted (by succesfulsuccessful, we mean, with no validation errors). Tapestry's default behavior is to redisplay the active page, and that occurs in a new request, with a new instance of the Address object (because the address field is not a peristent field).
...
Since Hibernate can work with so many different databases, we must explicitly add in the correct driver.
After changing the POM, you must re-execute the command mvn eclipse:eclipse -DdownloadSources=true
. Then, inside Eclipse, right click on the project (in Package Explorer) and select the "Refresh" menu item. You should also stop Jetty.
Hibernate Configuration
Hibernate has a master configuration file used to store connection and other data.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.connection.url">jdbc:hsqldb:./target/work/t5_tutorial1;shutdown=true</property>
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password"></property>
<property name="hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
</session-factory>
</hibernate-configuration>
|
Most of the configuration is to identify the JDBC driver and connection URL.
...
Code Block | ||
---|---|---|
| ||
package orgcom.apacheexample.tapestry5.tutorial.entities; import orgjavax.apache.tapestry5.beaneditor.NonVisualpersistence.Entity; import orgjavax.apache.tapestry5.beaneditor.Validatepersistence.GeneratedValue; import orgjavax.apache.tapestry5.tutorial.data.Honorificpersistence.GenerationType; import javax.persistence.EntityId; import javax.persistence.GeneratedValueorg.apache.tapestry5.beaneditor.NonVisual; import javax.persistence.GenerationType;org.apache.tapestry5.beaneditor.Validate; import javax.persistence.Idcom.example.tutorial.data.Honorific; @Entity public class Address { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @NonVisual public private Long id; public private Honorific honorific; @Validate("required") public private String firstName; @Validate("required") public private String lastName; public private String street1; privatepublic String street2; @Validate("required") privatepublic String city; @Validate("required") public private String state; @Validate("required,regexp") private String zip; private String email; private String phone; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Honorific getHonorific() { return honorific; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public String getStreet1() { return street1; } public String getStreet2() { return street2; } public String getCity() { return city; } public String getState() { return state; } public String getZip() { return zip; } public String getEmail() { return email; } public String getPhone() { return phone; } public void setCity(String city) { this.city = city; } public void setEmail(String email) { this.email = email; } public void setFirstName(String firstName) { this.firstName = firstName; } public void setHonorific(Honorific honorific) { this.honorific = honorific; } public void setLastName(String lastName) { this.lastName = lastName; } public void setPhone(String phone) { this.phone = phone; } public void setState(String state) { this.state = state; } public void setStreet1(String street1) { this.street1 = street1; } public void setStreet2(String street2) { this.street2 = street2; } public void setZip(String zip) { this.zip = zip; } } |
The Tapestry annotations, @NonVisual and @Validate, may be placed on the setter or getter method or on the field (as we have done here). As with the Hibernate annotations, putting the annotation on the field requires that the field name match the corresponding property name.
...