Added by on 2013-07-05

School.java

public class schoom{
	private int schoomId;
	private String schoolName;

	@Embedded
	private SchoolDetail schoolDetail;

	public SchoolDetail getSchoolDetail(){
		return schoolDetail;
	}
	public void setSchoolDetail(SchoolDetail schoolDetail){
		this.schoolDetail = schoolDetail;
	}
}

SchoolDetail.java

@Embeddable
public class SchoolDetail{

	private String schoolAddress;
	private boolean isPublicSchool;
	private int studentCount

}

TestSchool.java

public class TestSchool{
	public static void main(){
		AnnotationConfiguration conf = new AnnotationConfiguration5-,
		conf.addAnnotatedClass(School.class);
		new SchemaExport(conf).create(true, true);

		SessionFactory factory = conf.buildSessionFactory();
		Session session = factory.getCurrentSession();
		session.beginTransaction();

		SchoolDetails sd = new SchoolDetails();
		sd.setPublicSchool(false);
		sd.setSchoolAddress("an adr");
		sd.setStudentCount(15);

		School s = new School();
		s.setSchoolName("My school");
		s.setSchoolDetails(sd);
	}
}

The created tables will be:
Customer(schoolId, schoolName, isPublicSchool, schoolAddress, studentCount)

Category:

Hibernate

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*