org.hibernate.TransactionException: Transaction not successfully started
org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:183)
com.brand.admin.dao.jdbc.MembersDaoImpl.alertadmin(MembersDaoImpl.java:266)
com.brand.admin.service.impl.MembersServiceImpl.alertadmin(MembersServiceImpl.java:76)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
$Proxy3.alertadmin(Unknown Source)
com.brand.admin.action.MembersAction.adminloggin(MembersAction.java:671)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
sun.reflect.GeneratedMethodAccessor58.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:218)
java.security.AccessController.doPrivileged(Native Method)
org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102)
sun.reflect.GeneratedMethodAccessor62.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:218)
java.security.AccessController.doPrivileged(Native Method)
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
sun.reflect.GeneratedMethodAccessor61.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:218)
很多对数据库的操作都会出现这个问题!!求指教!!!!
7 个解决方案
#1
这一步操作的dao代码是:
public void alerttype(int id) {
Configuration cfg = new Configuration().configure();
SessionFactory factory = cfg.buildSessionFactory();
Session session = null;
try {
session = factory.openSession();
session.beginTransaction();
TMembers d = new TMembers();
d = (TMembers) session.get(TMembers.class,id);
d.setType(true);
session.update(d);
session.getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
session.getTransaction().rollback();
} finally {
if (session != null) {
session.close();
}
}
}
public void alerttype(int id) {
Configuration cfg = new Configuration().configure();
SessionFactory factory = cfg.buildSessionFactory();
Session session = null;
try {
session = factory.openSession();
session.beginTransaction();
TMembers d = new TMembers();
d = (TMembers) session.get(TMembers.class,id);
d.setType(true);
session.update(d);
session.getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
session.getTransaction().rollback();
} finally {
if (session != null) {
session.close();
}
}
}
#2
顶一下 防止沉
#3
来个人啊!!!!!
#4
Session session = null;
Transaction tx = null;
User user = null;
try {
session = HibernateSessionFactory.currentSession();
tx = session.beginTransaction();
Query query = session
.createQuery("from User where username=? and password=?");
query.setString(0, username.trim());
query.setString(1, password.trim());
user = (User) query.uniqueResult();
query = null;
tx.commit();
catch (HibernateException e) {
if (tx != null) {
tx.rollback();
}
throw e;
} finally {
HibernateSessionFactory.closeSession();
}
return user;
}
参考。
Transaction tx = null;
User user = null;
try {
session = HibernateSessionFactory.currentSession();
tx = session.beginTransaction();
Query query = session
.createQuery("from User where username=? and password=?");
query.setString(0, username.trim());
query.setString(1, password.trim());
user = (User) query.uniqueResult();
query = null;
tx.commit();
catch (HibernateException e) {
if (tx != null) {
tx.rollback();
}
throw e;
} finally {
HibernateSessionFactory.closeSession();
}
return user;
}
参考。
#5
我觉得应该有关你的事物问题
#6
根据你的异常信息判断,应该是session.getTransaction().rollback();这里异常。
异常信息写的很明确了: Transaction not successfully started
事务没有成功启动。
因为你Catch的是Exception,
session = factory.openSession();
session.beginTransaction();
这两个操作出现异常的时候也会Rollback,这时就会报你现在的异常信息了。
检查一下这两个操作是不是成功的吧。
异常信息写的很明确了: Transaction not successfully started
事务没有成功启动。
因为你Catch的是Exception,
session = factory.openSession();
session.beginTransaction();
这两个操作出现异常的时候也会Rollback,这时就会报你现在的异常信息了。
检查一下这两个操作是不是成功的吧。
#1
这一步操作的dao代码是:
public void alerttype(int id) {
Configuration cfg = new Configuration().configure();
SessionFactory factory = cfg.buildSessionFactory();
Session session = null;
try {
session = factory.openSession();
session.beginTransaction();
TMembers d = new TMembers();
d = (TMembers) session.get(TMembers.class,id);
d.setType(true);
session.update(d);
session.getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
session.getTransaction().rollback();
} finally {
if (session != null) {
session.close();
}
}
}
public void alerttype(int id) {
Configuration cfg = new Configuration().configure();
SessionFactory factory = cfg.buildSessionFactory();
Session session = null;
try {
session = factory.openSession();
session.beginTransaction();
TMembers d = new TMembers();
d = (TMembers) session.get(TMembers.class,id);
d.setType(true);
session.update(d);
session.getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
session.getTransaction().rollback();
} finally {
if (session != null) {
session.close();
}
}
}
#2
顶一下 防止沉
#3
来个人啊!!!!!
#4
Session session = null;
Transaction tx = null;
User user = null;
try {
session = HibernateSessionFactory.currentSession();
tx = session.beginTransaction();
Query query = session
.createQuery("from User where username=? and password=?");
query.setString(0, username.trim());
query.setString(1, password.trim());
user = (User) query.uniqueResult();
query = null;
tx.commit();
catch (HibernateException e) {
if (tx != null) {
tx.rollback();
}
throw e;
} finally {
HibernateSessionFactory.closeSession();
}
return user;
}
参考。
Transaction tx = null;
User user = null;
try {
session = HibernateSessionFactory.currentSession();
tx = session.beginTransaction();
Query query = session
.createQuery("from User where username=? and password=?");
query.setString(0, username.trim());
query.setString(1, password.trim());
user = (User) query.uniqueResult();
query = null;
tx.commit();
catch (HibernateException e) {
if (tx != null) {
tx.rollback();
}
throw e;
} finally {
HibernateSessionFactory.closeSession();
}
return user;
}
参考。
#5
我觉得应该有关你的事物问题
#6
根据你的异常信息判断,应该是session.getTransaction().rollback();这里异常。
异常信息写的很明确了: Transaction not successfully started
事务没有成功启动。
因为你Catch的是Exception,
session = factory.openSession();
session.beginTransaction();
这两个操作出现异常的时候也会Rollback,这时就会报你现在的异常信息了。
检查一下这两个操作是不是成功的吧。
异常信息写的很明确了: Transaction not successfully started
事务没有成功启动。
因为你Catch的是Exception,
session = factory.openSession();
session.beginTransaction();
这两个操作出现异常的时候也会Rollback,这时就会报你现在的异常信息了。
检查一下这两个操作是不是成功的吧。