I am using Eclipse, Xammp (tomcat and MySQL DB) and Hibernate.
this all works good, but I can't create that the ID from the Entity will be auto_increment in the Database
My Entity:
package com.jwt.hibernate.bean;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.annotations.GenericGenerator;
#Entity
public class User {
#Id
#GenericGenerator(name="generator", strategy="increment")
#GeneratedValue(generator="generator")
private Long userId;
private String userName;
private String password1;
private String email;
private String phone;
private String city;
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword1() {
return password1;
}
public void setPassword1(String password1) {
this.password1 = password1;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
I create a hbm.xml for this Entity with a Plugin from Hibernate and use Hibernate XML Mapping file(hbm.xml):
Created hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 06.05.2016 11:59:26 by Hibernate Tools 3.5.0.Final -->
<hibernate-mapping>
<class name="com.jwt.hibernate.bean.User" table="USER">
<id name="userId" type="java.lang.Long">
<column name="USERID" />
<generator class="assigned" />
</id>
<property name="userName" type="java.lang.String">
<column name="USERNAME" />
</property>
<property name="password1" type="java.lang.String">
<column name="PASSWORD1" />
</property>
<property name="email" type="java.lang.String">
<column name="EMAIL" />
</property>
<property name="phone" type="java.lang.String">
<column name="PHONE" />
</property>
<property name="city" type="java.lang.String">
<column name="CITY" />
</property>
</class>
</hibernate-mapping>
My hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="hbm2ddl.auto">create-drop</property>
<property name="show_sql">true</property>
<mapping resource="/com/jwt/hibernate/bean/User.hbm.xml" />
</session-factory>
</hibernate-configuration>
If i start my Code, the Console do:
Hibernate: drop table if exists USER
Hibernate: create table USER (USERID bigint not null, USERNAME varchar(255), PASSWORD1 varchar(255), EMAIL varchar(255), PHONE varchar(255), CITY varchar(255), primary key (USERID))
Every thing is fine but my ID isn't auto_increment and I don't know why.
I tried a lot of Annotations.
other Annotations for Example ManyToMany or ManyToOne works, but nut the #GeneratedValue
Use
<id name="userId" type="java.lang.Long">
<column name="USERID" />
<generator class="native" />
</id>
Instead of following line
<id name="userId" type="java.lang.Long">
<column name="USERID" />
<generator class="assigned" />
</id>
You can do use this annotations on your getUserId method :
#Id
#GenericGenerator(name = "id_generator", strategy = "increment")
#GeneratedValue(generator = "id_generator")
#Column(name = "id", unique = true, nullable = false)
public Long getUserId() {
return userId;
}
or you can also do this in your current code just specify #Column on getUserId method
#Column(name = "id", unique = true, nullable = false)
public Long getUserId() {
return userId;
}
If you will use annotations, this is pretty enough
#Id
#GeneratedValue
#Column(name = "id")
public Long getUserId() {
return userId;
}
Related
I have written few codes for inserting data into my SQL database. Actually, I am trying to learn Struts 2 with Hibernate. But, unfortunately I am facing a problem after submitting my form.
I could not find the reason for this error message. My try & catch block throws error like:
Exception in saveOrUpdate() Rollback :org.hibernate.MappingException: Unknown entity: v.esoft.pojos.Employee
Pojo(Employee.java):
#Entity
#Table(name = "employee", catalog = "eventusdb")
public class Employee implements java.io.Serializable {
private Integer empId;
private String name;
private String website;
public Employee() {
}
public Employee(String name, String website) {
this.name = name;
this.website = website;
}
#Id
#GeneratedValue(strategy = IDENTITY)
#Column(name = "emp_id", unique = true, nullable = false)
public Integer getEmpId() {
return this.empId;
}
public void setEmpId(Integer empId) {
this.empId = empId;
}
#Column(name = "name", nullable = false)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
#Column(name = "website", nullable = false, length = 65535)
public String getWebsite() {
return this.website;
}
public void setWebsite(String website) {
this.website = website;
}
}
also having Employee.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Sep 10, 2013 4:29:04 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="v.esoft.pojos.Employee" table="employee" catalog="eventusdb">
<id name="empId" type="java.lang.Integer">
<column name="emp_id" />
<generator class="identity" />
</id>
<property name="name" type="string">
<column name="name" not-null="true" />
</property>
<property name="website" type="string">
<column name="website" length="65535" not-null="true" />
</property>
</class>
</hibernate-mapping>
If the entity isn't mapped, you should inspect the hibernate configuration. Hibernate is ORM framework used to map pojos (entities) to the database schema objects. You didn't configure or hibernate couldn't find mapping for the object Employee. The configuration file is hibernate.cfg.xml should contain the mapping to the resource Employee.hbm.xml. Suppose this file is in the same folder as Employee class. Then the mapping will be
<mapping resource="v/esoft/pojos/Employee.hbm.xml"/>
Another approach if you used an annotation based configuration, then you should use class attribute to map to the pojo that contains Hibernate/JPA annotations.
<mapping class="v.esoft.pojos.Employee"/>
Note, annotation based Configuration might be different depending on version of Hibernate and may require additional libraries.
I am trying to insert data into a Patient table, which has a many-to-one relationship with Site. Site has a one-to-many relationship with Patient.
However, I get a org.postgresql.util.PSQLException: ERROR: insert or update on table "patients" violates foreign key constraint "fk_427e3ubwhw8n7a4id3mmrmjgj"
Detail: Key (patient_id)=(31) is not present in table "sites".
I have tried to create a set of patients, add my patient to this set, create a site object, then use this object to set the patients. I am not sure which part of this is going wrong.
Session session = this.getFactory().openSession();
Transaction transaction = null;
try{
transaction = session.beginTransaction();
Date parsedDob = Date.valueOf(dob);
Date parsedDateReg = Date.valueOf(dateReg);
Site site = new Site();
site.setSiteId(1);
IPatient p = new Patient();
p.setFirstName(firstName);
p.setLastName(lastName);
p.setDob(parsedDob);
p.setDateRegistered(parsedDateReg);
p.setSite(site);
Set<IPatient> patientSet = new HashSet<IPatient>();
patientSet.add(p);
site.setPatients(patientSet);
session.save(site);
session.save(p);
transaction.commit();
}catch(Exception e){
e.printStackTrace();
}
My Patient.hbm.xml file is:
<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.example.model">
<class name="Patient" table="patients">
<id name="patientId" column="patient_id">
<generator class="sequence" />
</id>
<version name="version" column="version" />
<property name="firstName" column="first_name" />
<property name="lastName" column="last_name" />
<property name="dob" column="dob" />
<property name="gender" column="gender" />
<property name="dateRegistered" column="date_registered" />
<many-to-one name="site" class="com.example.model.Site" not-null="true" />
<set name="visits" cascade="all">
<key column="visit_id" />
<one-to-many class="Visit" />
</set>
</class>
My Site.hmx.xml is:
<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.example.model">
<class name="Site" table="sites">
<id name="siteId" column="site_id">
<generator class="sequence" />
</id>
<version name="version" column="version" />
<property name="name" column="name" />
<set name="patients" cascade="all">
<key column="patient_id" />
<one-to-many class="Patient" />
</set>
</class>
My Patient.java
public class Patient implements IPatient{
private Integer version;
private Integer patientId;
private Set<IVisit> visits;
private Site site;
private String firstName;
private String lastName;
private Date dob;
private Gender gender;
private Date dateRegistered;
public Patient(){
}
}
My Site.java
public class Site {
private Integer siteId;
private Integer version;
private Set<IPatient> patients;
private String name;
public Site(){
}
}
After the line below you should save your site object to db;
site.setSiteId(1);
session.save(site);
After that you can set site object to patient;
p.setSite(site);
I have a table (node) with 3 data
- id(pk)
- question
- result
and 2 foreign key (many-to-one)
- LEFT_ID
- RIGHT_ID
here my hbm
<?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="com.beans.Nodes" table="node">
<id name="id" type="int" access="field">
<column name="id" />
<generator class="assigned" />
</id>
<property name="question" type="java.lang.String">
<column name="question" />
</property>
<property name="result" type="java.lang.String">
<column name="result" />
</property>
<many-to-one column="LEFT_ID" name="left" class="com.beans.Nodes" insert="false" update="false"></many-to-one>
<many-to-one column="RIGHT_ID" name="right" class="com.beans.Nodes" insert="false" update="false"></many-to-one>
</class>
</hibernate-mapping>
and my bean with getter/setter on LEFT/RIGHT_ID
#Entity
#Table (name = "node")
public class Nodes
{
#Id
#GeneratedValue (strategy = GenerationType.IDENTITY)
#Column(name="id")
private int id;
#Column (name = "question")
private String question;
#Column ( name = "result")
private String result;
private Nodes LEFT_ID;
private Nodes RIGHT_ID;
public Nodes getLeftNodes()
{
return LEFT_ID;
}
public void setLeftNodes(Nodes LEFT_ID)
{
this.LEFT_ID=LEFT_ID;
}
public Nodes getRightNodes()
{
return RIGHT_ID;
}
public void setRifhtNodes(Nodes right)
{
this.RIGHT_ID=right;
}
}
But when i deploy my project, i have this error
**Query: ReadAllQuery(referenceClass=Nodes sql="SELECT id, question, result, LEFT_ID_id, RIGHT_ID_id FROM node")**
When hibernate is a select, he change the name of the column. LEFT_ID becomes LEFT_ID_id and inevitably he finds nothing !
Why hibernate change the name of the LEFT_ID column ?
thanks
I try to create a one to one relationship between two tables.
One of them is Person:
public class Person implements Serializable {
static final long serialVersionUID = 1L;
private long id;
private String _email;
private String _pass;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getEmail() {
return _email;
}
public void set_email(String _email) {
this._email = _email;
}
public String getPass() {
return _pass;
}
public void set_pass(String _pass) {
this._pass = _pass;
}
}
and the second is ReqC2dmRegId table:
public class ReqC2dmRegId implements Serializable {
private static final long serialVersionUID = 1L;
Person person;
String C2dmid;
private long id;
public ReqC2dmRegId(){}
public String getC2dmid() {
return C2dmid;
}
public void setC2dmid(String c2dmid) {
C2dmid = c2dmid;
}
public ReqC2dmRegId(Person person, String C2dmid) {
super();
this.person = person;
this.C2dmid = C2dmid;
}
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
Now, in my program, I always create the Person first and only when I need I add this ReqC2dmRegId.
Now, what I try to do is to link this two tables. I mean, when I persist this ReqC2dmRegId (of course I add to the person in ReqC2dmRegId the right id) I want my ReqC2dmRegId to update or save a new row with the right Person id.
These are my hbm files:
ReqC2dmRegId.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Mar 26, 2012 11:29:57 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="c2dm.ReqC2dmRegId" table="REQC2DMREGID">
<id name="id" type="long">
<generator class="foreign">
<param name="property">person</param>
</generator>
</id>
<one-to-one name="person" class="Entities.Person" cascade="all" />
<property name="C2dmid" type="java.lang.String">
<column name="C2DMID" />
</property>
</class>
</hibernate-mapping>
Person.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Mar 26, 2012 11:29:57 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="Entities.Person" table="PERSON">
<id name="id" type="long">
<column name="ID" />
<generator class="increment" />
</id>
<property name="_email" type="java.lang.String" access="field">
<column name="_EMAIL" />
</property>
<property name="_pass" type="java.lang.String" access="field">
<column name="_PASS" />
</property>
</class>
</hibernate-mapping>
What am I doing wrong?
When I try to run:
//this should to update or save the object in DB
public void update (Object query){
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
//em.createNativeQuery(query).executeUpdate();
em.merge(query);
em.flush();
em.getTransaction().commit();
em.close();
}
I get :
attempted to assign id from null one-to-one property:Person
In the end, it should look like this:
Person
**id email _pass**
2 lala#gmail.com 1234
ReqC2dmRegId
**id REQC2DMREGID**
2 ffgghhjj
Update:
after i gave up try to understand way it's not working
i change my ReqC2dmRegId.hbm.xml
to look like this (many-to-one):
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated Mar 27, 2012 9:58:08 PM by Hibernate Tools 3.4.0.CR1 --> <hibernate-mapping>
<class name="c2dm.ReqC2dmRegId" table="REQC2DMREGID">
<id name="id" type="long">
<column name="ID" />
<generator class="identity" />
</id>
<many-to-one name="person" class="Entities.Person" fetch="join" unique="true" cascade="save-update" not-null="true" >
<column name="PERSON" />
</many-to-one>
<property name="C2dmid" type="java.lang.String">
<column name="C2DMID" />
</property>
</class> </hibernate-mapping>
and this is working fine the problem is when i try to modify ReqC2dmRegId table
with my update method it create a now row with the same personid
id person_id C2dmid
1 3 asd123
2 3 dfvghj
way it's not update the right row instated create a new one and although i make the "many to one" property to be unique="true"?
thanks in advance
You have to be clear about the kind of relation: Is one-to-one or many-to-one?
Look like is a many-to-one unidirectional relation.
Here is an example with Annotations:
#Entity
#Table(name="PERSON")
public class Person {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String _email;
private String _pass;
//getters and setters
}
And the other class:
#Entity
#Table(name="ReqC2dmRegId")
public class ReqC2dmRegId {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private int id;
#ManyToOne
#JoinColumn(name = "PERSON_ID")
private Person person;
//getters and setters
}
Two classes:
<class name="SpreadsheetImportTemplate" table="spreadsheetimport_template">
<id name="id" type="int" column="id" unsaved-value="0">
<generator class="native" />
</id>
<property name="name" type="java.lang.String" column="name" not-null="true" length="100" />
<many-to-one name="creator" class="org.openmrs.User" not-null="true" />
<property name="created" type="java.util.Date" column="date_created" not-null="true"
length="19" />
<many-to-one name="modifiedBy" column="changed_by" class="org.openmrs.User" not-null="false" />
<property name="modified" type="java.util.Date" column="date_changed" not-null="false" length="19" />
<!-- Associations -->
<!-- bi-directional one-to-many association to SpreadsheetImportTemplateColumn -->
<bag name="columns" cascade="all-delete-orphan" inverse="true">
<key column="template_id" not-null="true" />
<one-to-many class="SpreadsheetImportTemplateColumn" />
</bag>
</class>
<class name="SpreadsheetImportTemplateColumn" table="spreadsheetimport_template_column">
<id name="id" type="int" column="id" unsaved-value="0">
<generator class="native" />
</id>
<many-to-one name="template" class="SpreadsheetImportTemplate" column="template_id" />
<property name="columnName" type="java.lang.String" column="column_name" length="100" not-null="true" />
<property name="dbTableDotColumn" type="java.lang.String" column="db_table_dot_column" length="100" not-null="true"/>
<property name="extraData" type="java.lang.String" column="extra_data" length="100" not-null="false"/>
</class>
In java both have following with respective getters and setters:
public class SpreadsheetImportTemplate {
Integer id;
String name;
Collection<SpreadsheetImportTemplateColumn> columns = new ArrayList<SpreadsheetImportTemplateColumn>();
Date created;
Date modified;
User creator;
User modifiedBy;
public SpreadsheetImportTemplate() {
}
...
public class SpreadsheetImportTemplateColumn {
Integer id;
SpreadsheetImportTemplate template;
String columnName;
String dbTableDotColumn;
String extraData;
public SpreadsheetImportTemplateColumn() {
}
...
However, if we have a SpreadsheetImportTemplate template with some columns, and we do a template.remove(0) and then a Hibernate saveOrUpdate, the relevant SpreadsheetImportTemplateColumn does not get deleted from the database :(
Any help appreciated.
Fyi, here is the relevant SQL that creates the databases:
CREATE TABLE IF NOT EXISTS `spreadsheetimport_template` (
`id` int(32) NOT NULL auto_increment,
`name` varchar(100) NOT NULL,
`creator` int(11) NOT NULL default '0',
`date_created` datetime NOT NULL default '0000-00-00 00:00:00',
`changed_by` int(11) default NULL,
`date_changed` datetime default NULL,
PRIMARY KEY (`id`),
KEY `User who wrote this spreadsheet template` (`creator`),
KEY `User who changed this spreadsheet template` (`changed_by`),
CONSTRAINT `User who wrote this spreadsheet template` FOREIGN KEY (`creator`) REFERENCES `users` (`user_id`),
CONSTRAINT `User who changed this spreadsheet template` FOREIGN KEY (`changed_by`) REFERENCES `users` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `spreadsheetimport_template_column` (
`id` int(32) NOT NULL auto_increment,
`template_id` int(32) NOT NULL default '0',
`column_name` varchar(100) NOT NULL,
`db_table_dot_column` varchar(100) NOT NULL,
`extra_data` varchar(100),
PRIMARY KEY (`id`),
KEY `Spreadsheet template to which this column belongs` (`template_id`),
CONSTRAINT `Spreadsheet template to which this column belongs` FOREIGN KEY (`template_id`) REFERENCES `spreadsheetimport_template` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Just relevant part
SpreadsheetImportTemplate
public class SpreadsheetImportTemplate {
private Integer id;
public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; }
private Collection<SpreadsheetImportTemplateColumn> columns = new ArrayList<SpreadsheetImportTemplateColumn>();
public Collection<SpreadsheetImportTemplateColumn> getColumns() { return columns; }
public void setColumns(Collection<SpreadsheetImportTemplateColumn> columns) { this.columns = columns; }
/**
* set up both sides
*/
public void addColumn(SpreadsheetImportTemplateColumn column) {
getColumns().add(column);
column.setTemplate(this);
}
}
SpreadsheetImportTemplateColumn
public class SpreadsheetImportTemplateColumn {
private Integer id;
public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; }
private SpreadsheetImportTemplate template;
public SpreadsheetImportTemplate getTemplate() { return template; }
public void setTemplate(SpreadsheetImportTemplate template) { this.template = template; }
}
mapping
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="br.com._3589013.model.domain">
<class name="SpreadsheetImportTemplate">
<id name="id">
<generator class="native"/>
</id>
<bag name="columns" cascade="all,delete-orphan" inverse="true">
<key/>
<one-to-many class="SpreadsheetImportTemplateColumn"/>
</bag>
</class>
<class name="SpreadsheetImportTemplateColumn">
<id name="id">
<generator class="native"/>
</id>
<many-to-one name="template" class="SpreadsheetImportTemplate"/>
</class>
</hibernate-mapping>
Test
public class PersistenceTest {
private static SessionFactory sessionFactory;
private Serializable id;
#BeforeClass
public static void setUpClass() {
Configuration c = new Configuration();
c.addResource("mapping.hbm.3589013.xml");
sessionFactory = c.configure().buildSessionFactory();
}
#Before
public void setUp() throws Exception {
SpreadsheetImportTemplate sit = new SpreadsheetImportTemplate();
sit.addColumn(new SpreadsheetImportTemplateColumn());
Session session = sessionFactory.openSession();
session.beginTransaction();
id = session.save(sit);
session.getTransaction().commit();
}
#Test
public void removedOrphan() throws Exception {
Session session = sessionFactory.openSession();
session.beginTransaction();
List<SpreadsheetImportTemplateColumn> sitcList = session.createQuery("from SpreadsheetImportTemplateColumn").list();
assertTrue(sitcList.size() == 1);
SpreadsheetImportTemplate sit = (SpreadsheetImportTemplate) session.get(SpreadsheetImportTemplate.class, id);
sit.getColumns().remove(sitcList.get(0));
session.getTransaction().commit();
assertTrue(sit.getColumns().size() == 0);
}
}
It works fine!
I could not figure it out.
I hacked a work around:
public class SpreadsheetImportDAOImpl implements SpreadsheetImportDAO {
...
public SpreadsheetImportTemplate saveSpreadsheetImportTemplate(SpreadsheetImportTemplate template) {
// TODO: Hack - how does this get specified properly in hbm.xml files???
// Column processing: delete columns that must be deleted, make sure template field
// points to template
Iterator<SpreadsheetImportTemplateColumn> columnIterator = template.getColumns().iterator();
while (columnIterator.hasNext()) {
SpreadsheetImportTemplateColumn column = columnIterator.next();
if (column.isDeleted()) {
columnIterator.remove();
sessionFactory.getCurrentSession().delete(column);
} else {
column.setTemplate(template);
}
}
sessionFactory.getCurrentSession().saveOrUpdate(template);
return template;
}
...
}