background preloader

A blog about Programming, Web Development, Technologies & Internet

A blog about Programming, Web Development, Technologies & Internet

Hibernate One To Many Annotation tutorial with example. Hibernate annotations Welcome to the Hibernate Tutorial Series. In previous tutorial we saw how to implement One to Many relationship using XML mapping. In this tutorial we will modify the source code from previous One To Many XML mapping tutorial and add JPA/Annotation support to it. 1. Database Setup For this example, we will use MySQL database. 2. Download the source code: Hibernate-one-to-many-set-example.zip (9 KB) and import the project in Eclipse. 3. File: pom.xml <? 3. We are not going to use hibernate mapping files or hbm files as we will map the model using Java 5 Annotations. 4. File: Employee.java @ManyToOne annotation defines a single-valued association to another entity class that has many-to-one multiplicity. @JoinColumn is used to specify a mapped column for joining an entity association. File: Department.java @OneToMany annotation defines a many-valued association with one-to-many multiplicity. The association may be bidirectional. 5. File: hibernate.cfg.xml <? 6. 7. Output: 8. Download Source Code

HTML editor Hibernate Many To Many Annotation mapping tutorial example. Bi-Directional set mapping Welcome to the Hibernate Tutorial Series. In previous tutorial we saw how to implement Many to Many relationship using XML mapping. In this tutorial we will modify the source code from previous Many To Many XML mapping tutorial and add JPA/Annotation support to it. Let us see how to implement Many-to-Many relationship in Hibernate using Annotation. 1. Create Database For this example, we will MySQL database. 2. Download the source code: Hibernate-many-to-many-set-xml.zip (9 KB) and import the project in Eclipse. 3. File: pom.xml 3. We are not going to use hibernate mapping files or hbm files as we will map the model using Java 5 Annotations. 4. We will update Employee and Meeting model classes and add Annotations to map them with database table. File: Employee.java File: Meeting.java Let us understand the annotations we used here to map Many to many relationship. @ManyToMany – Is used to create many-to-many relationship between Employee and Meeting entities. 5. File: HibernateUtil.java 6. 7.

ProgrammerFish The search is over. Ricardo Boaro | Embarcadero MVP Using Facelets Templates - The Java EE 6 Tutorial JavaServer Faces technology provides the tools to implement user interfaces that are easy to extend and reuse. Templating is a useful Facelets feature that allows you to create a page that will act as the base, or template, for the other pages in an application. By using templates, you can reuse code and avoid recreating similarly constructed pages. Templating also helps in maintaining a standard look and feel in an application with a large number of pages. Table 5-2 lists Facelets tags that are used for templating and their respective functionality. Table 5-2 Facelets Templating Tags For more information on Facelets templating tags, see the documentation at The Facelets tag library includes the main templating tag ui:insert. Here is an example of a template saved as template.xhtml: <! The example page defines an XHTML page that is divided into three sections: a top section, a left section, and a main section.

dygraphs JavaScript Visualization Library JSF 2.0 + Spring + Hibernate integration example Here’s a long article to show you how to integrate JSF 2.0, Spring and Hibernate together. At the end of the article, you will create a page which display a list of the existing customer from database and a “add customer” function to allow user to add a new customer into database. P.S In this example, we are using MySQL database and deploy to Tomcat 6 web container. 1. Directory structure of this example 2. Create a customer table and insert 2 dummy records. DROP TABLE IF EXISTS `mkyongdb`. 3. A model class and Hibernate mapping file for customer table. File : Customer.java package com.mkyong.customer.model; import java.util.Date; public class Customer{ public long customerId; public String name; public String address; public Date createdDate; //getter and setter methods } File : Customer.hbm.xml 4. Spring’s BO and DAO classes for business logic and database interaction. File : CustomerBo.java File : CustomerBoImpl.java File : CustomerDao.java File : CustomerDaoImpl.java File : CustomerBean.xml 5. <?

Related: