本文整理汇总了Java中org.hibernate.Session.delete方法的典型用法代码示例。如果您正苦于以下问题:Java Session.delete方法的具体用法?Java Session.delete怎么用?Java Session.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.Session
的用法示例。
在下文中一共展示了Session.delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteComponentProfileByControlId
import org.hibernate.Session; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void deleteComponentProfileByControlId(String controlId, String name) {
DetachedCriteria detachedCriteria = DetachedCriteria.forClass(ComponentConfig.class);
detachedCriteria.add(Restrictions.eq("controlId", controlId));
detachedCriteria.add(Restrictions.eq("name", name));
Session session = this.getSessionFactory().openSession();
try {
org.hibernate.Criteria criteria = detachedCriteria.getExecutableCriteria(session);
List<ComponentConfig> list = criteria.list();
if (list.size() > 0) {
String hql = "delete " + ComponentConfigMember.class.getName()
+ " m where m.componentConfig.id = :configId";
session.createQuery(hql).setString("configId", list.get(0).getId()).executeUpdate();
session.delete(list.get(0));
}
} finally {
session.flush();
session.close();
}
}
示例2: doHandleRequest
import org.hibernate.Session; //导入方法依赖的package包/类
@Override
protected ModelAndView doHandleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String lobId=request.getParameter("lobId");
String deploymentId=request.getParameter("deploymentId");
String id=request.getParameter("id");
DesignerProcess process=new DesignerProcess();
process.setId(id);
Session session=hibernateDao.getSessionFactory().openSession();
try{
session.delete(process);
lobStoreService.deleteString(lobId);
bpmService.deleteDeployment(deploymentId);
}finally{
session.flush();
session.close();
}
return null;
}
示例3: unassign
import org.hibernate.Session; //导入方法依赖的package包/类
public String unassign(String managerExternalId, Session hibSession) {
Transaction tx = null;
try {
if (hibSession.getTransaction()==null || !hibSession.getTransaction().isActive())
tx = hibSession.beginTransaction();
ExamAssignment oldAssignment = new ExamAssignment(this);
setAssignedPeriod(null);
if (getAssignedRooms()==null) setAssignedRooms(new HashSet());
getAssignedRooms().clear();
setAssignedPreference(null);
HashSet otherExams = new HashSet();
for (Iterator j=getConflicts().iterator();j.hasNext();) {
ExamConflict conf = (ExamConflict)j.next();
for (Iterator i=conf.getExams().iterator();i.hasNext();) {
Exam x = (Exam)i.next();
if (!x.equals(this)) {
x.getConflicts().remove(conf);
otherExams.add(x);
}
}
hibSession.delete(conf);
j.remove();
}
ExamEvent event = getEvent();
if (event!=null) hibSession.delete(event);
hibSession.update(this);
for (Iterator i=otherExams.iterator();i.hasNext();)
hibSession.update((Exam)i.next());
SubjectArea subject = null;
Department dept = null;
for (Iterator i=new TreeSet(getOwners()).iterator();i.hasNext();) {
ExamOwner owner = (ExamOwner)i.next();
subject = owner.getCourse().getSubjectArea();
dept = subject.getDepartment();
break;
}
ChangeLog.addChange(hibSession,
TimetableManager.findByExternalId(managerExternalId),
getSession(),
this,
getName()+" ("+
(oldAssignment.getPeriod()==null?"N/A":oldAssignment.getPeriodAbbreviation()+" "+oldAssignment.getRoomsName(", "))+
" → N/A)",
ChangeLog.Source.EXAM_INFO,
ChangeLog.Operation.UNASSIGN,
subject,
dept);
if (tx!=null) tx.commit();
return null;
} catch (Exception e) {
if (tx!=null) tx.rollback();
e.printStackTrace();
return "Unassignment of "+getName()+" failed, reason: "+e.getMessage();
}
}
示例4: delete
import org.hibernate.Session; //导入方法依赖的package包/类
protected void delete(StandardEventNote note, SessionContext context, Session hibSession) {
if (note == null) return;
ChangeLog.addChange(hibSession,
context,
note,
note.getLabel(),
Source.SIMPLE_EDIT,
Operation.DELETE,
null,
note instanceof StandardEventNoteDepartment ? ((StandardEventNoteDepartment)note).getDepartment() : null);
hibSession.delete(note);
}
示例5: saveDefinitions
import org.hibernate.Session; //导入方法依赖的package包/类
@DataResolver
public void saveDefinitions(Collection<ReportDefinition> definitions){
Session session=this.getSessionFactory().openSession();
try{
IFileService fileService=ContextHolder.getBean(IFileService.BEAN_ID);
for(ReportDefinition definition:definitions){
EntityState state=EntityUtils.getState(definition);
if(state.equals(EntityState.NEW)){
definition.setCreateDate(new Date());
session.save(definition);
}
if(state.equals(EntityState.MODIFIED)){
session.update(definition);
}
if(state.equals(EntityState.DELETED)){
fileService.deleteUploadDefinition(definition.getReportFile());
String hql="delete "+ReportParameter.class.getName()+" where reportDefinitionId=:definitionId";
session.createQuery(hql).setString("definitionId", definition.getId()).executeUpdate();
hql="delete "+ReportResource.class.getName()+" where reportDefinitionId=:definitionId";
session.createQuery(hql).setString("definitionId", definition.getId()).executeUpdate();
session.delete(definition);
}
if(definition.getParameters()!=null){
this.saveParameters(definition.getParameters());
}
if(definition.getResources()!=null){
this.saveResources(definition.getResources());
}
}
}finally{
session.flush();
session.close();
}
}
示例6: saveGroups
import org.hibernate.Session; //导入方法依赖的package包/类
@DataResolver
public void saveGroups(Collection<Group> groups) throws Exception{
IUser user=ContextHolder.getLoginUser();
if(user==null){
throw new NoneLoginException("Please login first");
}
String companyId=user.getCompanyId();
if(StringUtils.isNotEmpty(getFixedCompanyId())){
companyId=getFixedCompanyId();
}
Session session=this.getSessionFactory().openSession();
try{
for(Group g:groups){
EntityState state=EntityUtils.getState(g);
if(state.equals(EntityState.NEW)){
g.setId(UUID.randomUUID().toString());
g.setCompanyId(companyId);
g.setCreateDate(new Date());
session.save(g);
}else if(state.equals(EntityState.MODIFIED)){
session.update(g);
}else if(state.equals(EntityState.DELETED)){
roleService.deleteRoleMemeber(g.getId(), MemberType.Group);
groupService.deleteGroupMemeber(g.getId(), MemberType.Group);
session.delete(g);
}
}
}finally{
session.flush();
session.close();
}
}
示例7: delete
import org.hibernate.Session; //导入方法依赖的package包/类
protected void delete(InstructorAttributeType type, SessionContext context, Session hibSession) {
if (type == null) return;
ChangeLog.addChange(hibSession,
context,
type,
type.getReference(),
Source.SIMPLE_EDIT,
Operation.DELETE,
null,
null);
hibSession.delete(type);
}
示例8: destroy
import org.hibernate.Session; //导入方法依赖的package包/类
/**
* Delete a Channel
* @param id channel ID.
* @return A response.
*/
@DELETE
@Path("{id}/")
public Response destroy(@PathParam("id") Long id) {
LOGGER.info("#DELETE " + id);
Response response = null;
if (this.authorization) {
Session session = HibernateUtil.getSessionFactory().openSession();
try {
session.beginTransaction();
Channel channel = session.get(Channel.class, id);
if (channel == null) {
response = Error.notFound(String.valueOf(id))
.getResponse();
LOGGER.warning("#DELETE {" + id + "} " + response.toString());
} else {
session.delete(channel);
response = Response
.ok(channel)
.build();
LOGGER.info("#DELETE {" + id + "} " + response.toString());
}
session.getTransaction().commit();
session.close();
} catch (Exception exception) {
response = Error.internalServer(exception)
.getResponse();
LOGGER.warning("#DELETE {" + id + "} " + exception.getLocalizedMessage());
session.getTransaction().rollback();
}
} else {
response = this.getUnauthorization();
}
return response;
}
示例9: delete
import org.hibernate.Session; //导入方法依赖的package包/类
protected void delete(PosMajor major, SessionContext context, Session hibSession) {
if (major == null) return;
ChangeLog.addChange(hibSession,
context,
major,
major.getCode() + " " + major.getName(),
Source.SIMPLE_EDIT,
Operation.DELETE,
null,
null);
hibSession.delete(major);
}
示例10: remove
import org.hibernate.Session; //导入方法依赖的package包/类
public void remove(Long piid) {
if( piid == null)
throw new PersistentVarsException("Could not remove properties for 'null' piid");
Session session = null;
Transaction transaction = null;
try {
session = this.sessionFactory.openSession();
transaction = session.beginTransaction();
Collection<String> keys = getKeys(piid, null, null);
for(String key : keys)
session.delete(getItem(session, piid, key));
transaction.commit();
} catch( HibernateException hibernateException ) {
throw new PersistentVarsException("Could not remove all keys: " + hibernateException.getMessage());
} finally {
// Rollback if 'commit' failed
if(transaction != null && transaction.isActive())
transaction.rollback();
if (session != null)
session.close();
}
}
示例11: deleteUploadDefinition
import org.hibernate.Session; //导入方法依赖的package包/类
public void deleteUploadDefinition(String id) {
Session session=this.getSessionFactory().openSession();
try{
UploadDefinition definition=(UploadDefinition)session.get(UploadDefinition.class, id);
if(definition==null){
throw new RuntimeException("Upload definition ["+id+"] is not exist!");
}
if(StringUtils.isEmpty(definition.getUploadProcessorKey())){
throw new RuntimeException("Upload definition ["+definition.getId()+"] has not set processor!");
}
String key=definition.getUploadProcessorKey();
IFileProcessor targetProcessor=null;
for(IFileProcessor processor:processors){
if(processor.key().equals(key)){
targetProcessor=processor;
break;
}
}
if(targetProcessor==null){
throw new RuntimeException("The processor ["+key+"] is not exist!");
}
targetProcessor.deleteFile(definition);
session.delete(definition);
}finally{
session.flush();
session.close();
}
}
示例12: removeProcessInstances
import org.hibernate.Session; //导入方法依赖的package包/类
private void removeProcessInstances(ProcessInstance pi,Session session){
long pid=pi.getParentId();
if(pid>0){
ProcessInstance parent=(ProcessInstance)session.get(ProcessInstance.class, pid);
parent.setState(ProcessInstanceState.End);
session.delete(parent);
removeProcessInstances(parent,session);
}
}
示例13: deleteClasses
import org.hibernate.Session; //导入方法依赖的package包/类
private void deleteClasses(InstructionalOfferingModifyForm frm, InstrOfferingConfig ioc, Session hibSession, HashMap tmpClassIdsToRealClasses){
if (ioc.getSchedulingSubparts() != null) {
SchedulingSubpart ss = null;
ArrayList lst = new ArrayList();
ArrayList subpartList = new ArrayList(ioc.getSchedulingSubparts());
Collections.sort(subpartList, new SchedulingSubpartComparator());
for(Iterator it = subpartList.iterator(); it.hasNext();){
ss = (SchedulingSubpart) it.next();
if (ss.getParentSubpart() == null){
buildClassList(ss.getClasses(), lst);
}
}
Class_ c;
for (int i = (lst.size() - 1); i >= 0; i--){
c = (Class_) lst.get(i);
if (!frm.getClassIds().contains(c.getUniqueId().toString()) && !tmpClassIdsToRealClasses.containsValue(c)){
if (c.getParentClass() != null){
Class_ parent = c.getParentClass();
parent.getChildClasses().remove(c);
hibSession.update(parent);
}
c.getSchedulingSubpart().getClasses().remove(c);
if (c.getPreferences() != null)
c.getPreferences().removeAll(c.getPreferences());
c.deleteAllDependentObjects(hibSession, false);
hibSession.delete(c);
}
}
}
}
示例14: delete
import org.hibernate.Session; //导入方法依赖的package包/类
protected void delete(RoomFeatureType type, SessionContext context, Session hibSession) {
if (type == null) return;
ChangeLog.addChange(hibSession,
context,
type,
type.getReference(),
Source.SIMPLE_EDIT,
Operation.DELETE,
null,
null);
hibSession.delete(type);
}
示例15: deleteEntity
import org.hibernate.Session; //导入方法依赖的package包/类
public void deleteEntity(Object entity) {
Session session = hibernateTemplate.getSessionFactory().openSession();
org.hibernate.Transaction tx = session.beginTransaction();
session.delete(entity);
try {
tx.commit();
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
}
session.close();
}