<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="contact.Person" table="Person"> <id name="id" type="string" unsaved-value="null"> <generator class="assigned"/> </id> <property name="first"/> <property name="last"/> <property name="full" formula="(select count(*) from PERSON )"/> </class> </hibernate-mapping>
----------------------------- package contact; import org.hibernate.SessionFactory; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration;
public class PersonTest { public static void main(String[] args) { SessionFactory factory=new Configuration().configure().buildSessionFactory(); Session session=factory.openSession(); Transaction tx=session.beginTransaction(); Person p1=new Person(); p1.setId("P1"); p1.setFirst("Micky"); p1.setLast("Mouse"); session.save(p1); tx.commit();
session.flush();
Person p2=(Person)session.load(Person.class,"P1"); System.out.println("Full - "+p2.getFull()); session.close(); } }
-------------------------------------
package contact; public class Person { private String id,first,last,full; public Person() { } public void setId(String id) { this.id=id; } public void setFirst(String first) { this.first=first; } public void setLast(String last) { this.last=last; } public void setFull(String full) { this.full=full; } public String getId() { return id; } public String getFirst() { return first; } public String getLast() { return last; } public String getFull() { return full; } } ----------------------
im using the following configuration for column formula.
but when i try to get
System.out.println("Full - "+p2.getFull());
it gives me null value.
plz help
|