本文整理汇总了Java中org.hibernate.Session.save方法的典型用法代码示例。如果您正苦于以下问题:Java Session.save方法的具体用法?Java Session.save怎么用?Java Session.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.Session
的用法示例。
在下文中一共展示了Session.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveList
import org.hibernate.Session; //导入方法依赖的package包/类
public final static boolean saveList(List<? extends BaseRelationalDatabaseDomain> list){
Session session = null;
try {
session = getSession();
beginTransaction();
for (Object obj:list) {
session.save(obj);
}
return managTransaction(true);
} catch (Exception e) {
setException(e);
return managTransaction(false);
}finally{
closeSession();
}
}
示例2: saveChenScoreMaps
import org.hibernate.Session; //导入方法依赖的package包/类
/**
* 矩陈评分题
* @param surveyAnswer
* @param chenScoreMaps
* @param session
* @return
*/
private int saveChenScoreMaps(SurveyAnswer surveyAnswer,
Map<String, Object> chenScoreMaps, Session session) {
String surveyId=surveyAnswer.getSurveyId();
String surveyAnswerId=surveyAnswer.getId();
int answerQuCount=0;
if(chenScoreMaps!=null){
for (String key : chenScoreMaps.keySet()) {
String quId=key;
Map<String,Object> mapRows=(Map<String, Object>) chenScoreMaps.get(key);
for (String keyRow : mapRows.keySet()) {
String rowId=keyRow;
Map<String, Object> mapRow=(Map<String, Object>) mapRows.get(keyRow);
for (String keyCol : mapRow.keySet()) {
answerQuCount++;
String colId=keyCol;
String answerValue=mapRow.get(keyCol).toString();
AnChenScore anChenScore=new AnChenScore(surveyId,surveyAnswerId,quId,rowId,colId,answerValue);
session.save(anChenScore);
}
}
}
}
return answerQuCount;
}
示例3: saveProcessDef
import org.hibernate.Session; //导入方法依赖的package包/类
private void saveProcessDef(NewDeployment deployment,String xmlData) throws Exception{
DeploymentImpl deploy=(DeploymentImpl)deployment;
ProcessDefinition pd=(ProcessDefinition)deploy.getObjects().values().iterator().next();
String deploymentId=pd.getDeploymentId();
String name=pd.getName();
int version=pd.getVersion();
DesignerProcess process=new DesignerProcess();
process.setDeploymentId(deploymentId);
process.setName(name);
process.setCreateDate(new Date());
Session session=hibernateDao.getSessionFactory().openSession();
try{
process.setVersion(version);
String lobId=lobStoreService.storeString(xmlData);
process.setLobId(lobId);
process.setId(UUID.randomUUID().toString());
session.save(process);
}finally{
session.flush();
session.close();
}
}
示例4: addProcessDefinition
import org.hibernate.Session; //导入方法依赖的package包/类
private void addProcessDefinition(String processDefinitionId){
Session session=this.getSessionFactory().openSession();
IUser user=ContextHolder.getLoginUser();
String companyId=null;
if(user!=null){
companyId=user.getCompanyId();
}
String fixedCompanyId=Configure.getString("bdf2.jbpm4.fixedCompanyId");
if(StringUtils.isEmpty(fixedCompanyId)){
fixedCompanyId=Configure.getString(IDao.FIXED_COMPANY_ID);
}
if(StringUtils.isNotEmpty(fixedCompanyId)){
companyId=fixedCompanyId;
}
try{
com.bstek.bdf2.jbpm4.model.ProcessDefinition pd=new com.bstek.bdf2.jbpm4.model.ProcessDefinition();
pd.setCompanyId(companyId);
pd.setId(processDefinitionId);
pd.setCreateDate(new Date());
session.save(pd);
}finally{
session.flush();
session.close();
}
}
示例5: saveOrUpdate
import org.hibernate.Session; //导入方法依赖的package包/类
/**
* 如果数据库有obj对象就update否则save
* @param obj
* @return
*/
public final static boolean saveOrUpdate(BaseRelationalDatabaseDomain obj){
Session session = null;
try {
session = getSession();
beginTransaction();
if (BaseUtil.isObjEmpty(DomainUtil.getDomainId(obj))) {
return save(obj);
}else {
BaseRelationalDatabaseDomain smartGet = smartGet(obj);
if (smartGet != null) {
session.evict(smartGet);
session.update(obj);
}else {
session.save(obj);
}
}
return managTransaction(true);
} catch (Exception e) {
setException(e);
return managTransaction(false);
}finally{
closeSession();
}
}
示例6: saveCompChehRadioMaps
import org.hibernate.Session; //导入方法依赖的package包/类
private int saveCompChehRadioMaps(SurveyAnswer surveyAnswer,
Map<String, Object> compChenRadioMaps, Session session) {
String surveyId=surveyAnswer.getSurveyId();
String surveyAnswerId=surveyAnswer.getId();
int answerQuCount=0;
if(compChenRadioMaps!=null){
for (String key : compChenRadioMaps.keySet()) {
String quId=key;
Map<String,Object> mapRows=(Map<String, Object>) compChenRadioMaps.get(key);
for (String keyRow : mapRows.keySet()) {
String rowId=keyRow;
Map<String, Object> mapRow=(Map<String, Object>) mapRows.get(keyRow);
for (String keyCol : mapRow.keySet()) {
answerQuCount++;
String colId=keyCol;
String optionId=mapRow.get(keyCol).toString();
AnCompChenRadio anCompChenRadio=new AnCompChenRadio(surveyId,surveyAnswerId,quId,rowId,colId,optionId);
session.save(anCompChenRadio);
}
}
}
}
return answerQuCount;
}
示例7: saveImageCategory
import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public boolean saveImageCategory(Image_Category image_Category) {
Session session = HibernateUtils.getSession(); //生成session实例
Transaction tx = session.beginTransaction(); //创建transaction实例
try {
session.save(image_Category);
tx.commit(); //提交事务
return true;
} catch (Exception e) {
e.printStackTrace();
tx.rollback(); //回滚事务
return false;
}finally {
HibernateUtils.closeSession(); //关闭Session实例
}
}
示例8: createAdmin
import org.hibernate.Session; //导入方法依赖的package包/类
public static void createAdmin() {
Session session = HibernateUtil.getSession();
Transaction tx = null;
User newUser = new User("John", "Doe", "admin", "[email protected]", "password", 2);
try {
tx = session.beginTransaction();
session.save(newUser);
tx.commit();
System.out.println("User: '" + newUser.getUsername() + "' has been successfully created!");
} catch (HibernateException he) {
if (tx != null) {
tx.rollback();
}
System.out.println("User creation failed!");
he.printStackTrace();
} finally {
session.close();
}
}
示例9: hibernate
import org.hibernate.Session; //导入方法依赖的package包/类
@Test
public void hibernate() {
SessionFactory sessionFactory = createSessionFactory(false);
Session session = sessionFactory.openSession();
Employee employee = new Employee();
session.beginTransaction();
session.save(employee);
session.getTransaction().commit();
session.close();
sessionFactory.close();
assertNotNull(employee.id);
List<MockSpan> finishedSpans = mockTracer.finishedSpans();
assertEquals(8, finishedSpans.size());
checkSpans(finishedSpans);
assertNull(mockTracer.activeSpan());
}
示例10: execute
import org.hibernate.Session; //导入方法依赖的package包/类
public Blob execute(Context context) {
Session session=context.getSession();
if(update){
Query query=session.createQuery("delete from "+Blob.class.getName()+" where processId=:processId");
query.setLong("processId", processId);
query.executeUpdate();
}
Blob lob=new Blob();
lob.setId(IDGenerator.getInstance().nextId());
lob.setBlobValue(processRes);
lob.setName(name);
lob.setProcessId(processId);
session.save(lob);
return lob;
}
示例11: execute
import org.hibernate.Session; //导入方法依赖的package包/类
public void execute(JobExecutionContext context) throws JobExecutionException {
DetectionJobDetail jobDetail=(DetectionJobDetail)context.getJobDetail();
Session session=jobDetail.getSessionFactory().openSession();
try {
String currentInstanceName=jobDetail.getCurrentInstanceName();
Operation operation=detection(session,jobDetail.getJobInstanceNames(),currentInstanceName);
if(operation.equals(Operation.reset)){
SchedulerService service=jobDetail.getSchedulerService();
service.resetScheduer();
Heartbeat beat=new Heartbeat();
Calendar c=Calendar.getInstance();
c.setTime(new Date());
c.add(Calendar.SECOND, 1);
beat.setDate(c.getTime());
beat.setId(UUID.randomUUID().toString());
beat.setInstanceName(currentInstanceName);
session.save(beat);
initHeartJob(currentInstanceName, service.getScheduler());
}
} catch (Exception e) {
throw new JobExecutionException(e);
}finally{
session.flush();
session.close();
}
}
示例12: savePostions
import org.hibernate.Session; //导入方法依赖的package包/类
@DataResolver
public void savePostions(final Collection<DefaultPosition> positions) {
Session session = this.getSessionFactory().openSession();
try {
IUser user = ContextHolder.getLoginUser();
if (user == null) {
throw new NoneLoginException("Please login first");
}
String companyId = user.getCompanyId();
if (StringUtils.isNotEmpty(getFixedCompanyId())) {
companyId = getFixedCompanyId();
}
for (DefaultPosition position : positions) {
EntityState state = EntityUtils.getState(position);
if (state.equals(EntityState.NEW)) {
position.setCompanyId(companyId);
position.setCreateDate(new Date());
session.save(position);
} else if (state.equals(EntityState.MODIFIED)) {
session.update(position);
} else if (state.equals(EntityState.DELETED)) {
roleService.deleteRoleMemeber(position.getId(), MemberType.Position);
groupService.deleteGroupMemeber(position.getId(), MemberType.Position);
positionService.deleteUserPosition(position.getId());
session.delete(position);
}
}
} finally {
session.flush();
session.close();
}
}
示例13: saveSorts
import org.hibernate.Session; //导入方法依赖的package包/类
@DataResolver
public void saveSorts(Collection<ComponentSort> sorts,String url,String parentComponentId,String controlId,String assignTargetId,String type){
Session session=this.getSessionFactory().openSession();
try{
this.checkCompoentInfo(session, url, parentComponentId, controlId, assignTargetId, type);
session.createQuery("delete "+ComponentSort.class.getName()+" where parentComponentId=:parentComponentId").setString("parentComponentId",parentComponentId).executeUpdate();
for(ComponentSort sort:sorts){
sort.setId(UUID.randomUUID().toString());
session.save(sort);
}
}finally{
session.flush();
session.close();
}
}
示例14: add
import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public boolean add(CourseBean courseBean) throws Exception {
if (courseBean == null) {
return false;
}
Session session = sessionFactory.getCurrentSession();
session.save(courseBean);
return true;
}
示例15: addPersonToAccount
import org.hibernate.Session; //导入方法依赖的package包/类
public Long addPersonToAccount(Long personId, Account account) {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
Person aPerson = session.load(Person.class, personId);
account.setPerson(aPerson);
Long accountId = (Long)session.save(account);
session.getTransaction().commit();
return accountId;
}