本文整理汇总了Java中org.hibernate.Session.saveOrUpdate方法的典型用法代码示例。如果您正苦于以下问题:Java Session.saveOrUpdate方法的具体用法?Java Session.saveOrUpdate怎么用?Java Session.saveOrUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.Session
的用法示例。
在下文中一共展示了Session.saveOrUpdate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import org.hibernate.Session; //导入方法依赖的package包/类
protected void update(CourseCreditUnitType credit, Record record, SessionContext context, Session hibSession) {
if (credit == null) return;
if (ToolBox.equals(credit.getReference(), record.getField(0)) &&
ToolBox.equals(credit.getLabel(), record.getField(1)) &&
ToolBox.equals(credit.getAbbreviation(), record.getField(2))) return;
credit.setReference(record.getField(0));
credit.setLabel(record.getField(1));
credit.setAbbreviation(record.getField(2));
hibSession.saveOrUpdate(credit);
ChangeLog.addChange(hibSession,
context,
credit,
credit.getReference() + " " + credit.getLabel(),
Source.SIMPLE_EDIT,
Operation.UPDATE,
null,
null);
}
示例2: updateBook
import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public int updateBook(long ISBN, int price) {
// TODO Auto-generated method stub
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
try {
Book book = session.get(Book.class, ISBN);
book.setPrice(price);
session.saveOrUpdate(book);
transaction.commit();
session.close();
return 1;
} catch (DataAccessException exception) {
exception.printStackTrace();
}
return 0;
}
示例3: update
import org.hibernate.Session; //导入方法依赖的package包/类
protected void update(AcademicClassification clasf, Record record, SessionContext context, Session hibSession) {
if (clasf == null) return;
if (ToolBox.equals(clasf.getExternalUniqueId(), record.getField(0)) &&
ToolBox.equals(clasf.getCode(), record.getField(1)) &&
ToolBox.equals(clasf.getName(), record.getField(2))) return;
clasf.setExternalUniqueId(record.getField(0));
clasf.setCode(record.getField(1));
clasf.setName(record.getField(2));
hibSession.saveOrUpdate(clasf);
ChangeLog.addChange(hibSession,
context,
clasf,
clasf.getCode() + " " + clasf.getName(),
Source.SIMPLE_EDIT,
Operation.UPDATE,
null,
null);
}
示例4: addBook
import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public int addBook(Book book) {
// TODO Auto-generated method stub
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
try {
session.saveOrUpdate(book);
transaction.commit();
session.close();
return 1;
} catch (DataAccessException exception) {
exception.printStackTrace();
}
return 0;
}
示例5: update
import org.hibernate.Session; //导入方法依赖的package包/类
protected void update(PositionType position, Record record, SessionContext context, Session hibSession) {
if (position == null) return;
DecimalFormat df = new DecimalFormat("0000");
if (ToolBox.equals(position.getReference(), record.getField(0)) &&
ToolBox.equals(position.getLabel(), record.getField(1)) &&
ToolBox.equals(df.format(position.getSortOrder()), record.getField(2))) return;
position.setReference(record.getField(0));
position.setLabel(record.getField(1));
position.setSortOrder(Integer.valueOf(record.getField(2)));
hibSession.saveOrUpdate(position);
ChangeLog.addChange(hibSession,
context,
position,
position.getReference() + " " + position.getLabel(),
Source.SIMPLE_EDIT,
Operation.UPDATE,
null,
null);
}
示例6: update
import org.hibernate.Session; //导入方法依赖的package包/类
protected void update(EventDateMapping mapping, Record record, SessionContext context, Session hibSession) {
try {
if (mapping == null) return;
Formats.Format<Date> dateFormat = Formats.getDateFormat(Formats.Pattern.DATE_EVENT);
if (ToolBox.equals(dateFormat.format(mapping.getClassDate()), record.getField(0)) &&
ToolBox.equals(dateFormat.format(mapping.getEventDate()), record.getField(1)) &&
ToolBox.equals(mapping.getNote(), record.getField(2))) return;
mapping.setClassDate(dateFormat.parse(record.getField(0)));
mapping.setEventDate(dateFormat.parse(record.getField(1)));
mapping.setNote(record.getField(2));
hibSession.saveOrUpdate(mapping);
ChangeLog.addChange(hibSession,
context,
mapping,
dateFormat.format(mapping.getClassDate()) + " → " + dateFormat.format(mapping.getEventDate()),
Source.SIMPLE_EDIT,
Operation.UPDATE,
null,
null);
} catch (ParseException e) {
throw new GwtRpcException(e.getMessage(), e);
}
}
示例7: addOrUpdate
import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public boolean addOrUpdate(StatusBean statusBean) {
if (statusBean == null) {
return false;
}
Session session = sessionFactory.getCurrentSession();
session.saveOrUpdate(statusBean);
return true;
}
示例8: save
import org.hibernate.Session; //导入方法依赖的package包/类
public void save(HibernatePersistentVarsItem item) {
if( item == null)
throw new PersistentVarsException("Could not save 'null' PropertyItem");
Session session = null;
Transaction transaction = null;
try {
session = this.sessionFactory.openSession();
transaction = session.beginTransaction();
session.saveOrUpdate(item);
session.flush();
transaction.commit();
} catch (HibernateException hibernateException) {
throw new PersistentVarsException("Could not save key '" + item.getKey() + "':" + hibernateException.getMessage());
} finally {
if (transaction != null && transaction.isActive())
transaction.rollback();
if (session != null)
session.close();
}
}
示例9: saveQuOrderby
import org.hibernate.Session; //导入方法依赖的package包/类
/**
* 保存排序题
* @param entity
* @param session
*/
private void saveQuOrderby(Question entity, Session session) {
List<QuOrderby> quOrderbys=entity.getQuOrderbys();
for (QuOrderby quOrderby : quOrderbys) {
quOrderby.setQuId(entity.getId());
session.saveOrUpdate(quOrderby);
}
}
示例10: update
import org.hibernate.Session; //导入方法依赖的package包/类
protected void update(StandardEventNote note, Record record, SessionContext context, Session hibSession) {
if (note == null) return;
if (ToolBox.equals(note.getReference(), record.getField(0)) && ToolBox.equals(note.getNote(), record.getField(1))) return;
note.setReference(record.getField(0));
note.setNote(record.getField(1));
hibSession.saveOrUpdate(note);
ChangeLog.addChange(hibSession,
context,
note,
note.getReference(),
Source.SIMPLE_EDIT,
Operation.UPDATE,
null,
note instanceof StandardEventNoteDepartment ? ((StandardEventNoteDepartment)note).getDepartment() : null);
}
示例11: update
import org.hibernate.Session; //导入方法依赖的package包/类
public void update(Account account) {
Session session = null;
try {
session = this.sessionFactory.openSession();
session.saveOrUpdate(account);
session.flush();
} finally {
this.closeSessionIfNecessary(session);
}
}
示例12: saveOptions
import org.hibernate.Session; //导入方法依赖的package包/类
private void saveOptions(Question entity, Session session) {
List<QuChenOption> options=entity.getOptions();
String quId=entity.getId();
for (QuChenOption quChenOption : options) {
quChenOption.setQuId(quId);
session.saveOrUpdate(quChenOption);
}
}
示例13: execute
import org.hibernate.Session; //导入方法依赖的package包/类
public void execute(JobExecutionContext context) throws JobExecutionException {
HeartJobDetail detail=(HeartJobDetail)context.getJobDetail();
String instanceName=detail.getCurrentInstanceName();
Session session=detail.getSessionFactory().openSession();
try{
String hql="from "+Heartbeat.class.getName()+" b where b.instanceName=:instanceName order by b.date desc";
Query query=session.createQuery(hql).setString("instanceName",instanceName);
@SuppressWarnings("unchecked")
List<Heartbeat> beats=query.list();
Date now=new Date();
Heartbeat beat=null;
if(beats.size()>0){
beat=beats.get(0);
}else{
beat=new Heartbeat();
beat.setId(UUID.randomUUID().toString());
beat.setInstanceName(instanceName);
}
beat.setDate(now);
session.saveOrUpdate(beat);
}catch(Exception ex){
throw new JobExecutionException(ex);
}finally{
session.flush();
session.close();
}
}
示例14: update
import org.hibernate.Session; //导入方法依赖的package包/类
protected void update(Location location, Record record, SessionContext context, Session hibSession) {
if (location == null) return;
Integer status = record.getField(3) == null || record.getField(3).isEmpty() ? null : Integer.parseInt(record.getField(3));
String note = (record.getField(4) == null || record.getField(4).isEmpty() ? null : record.getField(4));
Integer breakTime = null;
try {
breakTime = (record.getField(5) == null || record.getField(5).isEmpty() ? null : Integer.parseInt(record.getField(5)));
} catch (NumberFormatException e) {}
if (ToolBox.equals(location.getEventStatus(), status) &&
ToolBox.equals(location.getNote(), note) &&
ToolBox.equals(location.getBreakTime(), breakTime)) return;
boolean noteChanged = !ToolBox.equals(location.getNote(), note);
location.setEventStatus(status);
location.setNote(note);
location.setBreakTime(breakTime);
hibSession.saveOrUpdate(location);
ChangeLog.addChange(hibSession,
context,
location,
location.getLabel() + ": " + location.getEffectiveEventStatus() + (location.getEventStatus() == null ? " (Default)" : ""),
Source.SIMPLE_EDIT,
Operation.UPDATE,
null,
location.getEventDepartment());
if (noteChanged)
ChangeLog.addChange(hibSession,
context, location, (location.getNote() == null || location.getNote().isEmpty() ? "-" : location.getNote()),
ChangeLog.Source.ROOM_EDIT, ChangeLog.Operation.NOTE, null, location.getControllingDepartment());
}
示例15: saveQuScore
import org.hibernate.Session; //导入方法依赖的package包/类
/**
* 保存评分题
* @param entity
* @param session
*/
private void saveQuScore(Question entity, Session session) {
List<QuScore> quScores=entity.getQuScores();
for (QuScore quScore : quScores) {
quScore.setQuId(entity.getId());
session.saveOrUpdate(quScore);
}
}