下面是console出来的信息2010-3-29 19:03:12 per.jsp.entity.EntityManagerHelper log
信息: finding all User instances
110 jsf_HelloWorldPU INFO [main] openjpa.Runtime - Starting OpenJPA 1.2.0
235 jsf_HelloWorldPU INFO [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.MySQLDictionary".
1031 jsf_HelloWorldPU INFO [main] openjpa.Enhance - Creating subclass for "[class per.jsp.entity.User]". This means that your application will be less efficient and will consume more memory than it would if you ran the OpenJPA enhancer. Additionally, lazy loading will not be available for one-to-one and many-to-one persistent attributes in types using field access; they will be loaded eagerly instead.
2010-3-29 19:03:13 per.jsp.entity.EntityManagerHelper log
信息: finding User instance with id: 1
2 (这两条是我打印出来的,即它能从数据库里取出来)
pcenshao
2010-3-29 19:03:13 per.jsp.entity.EntityManagerHelper log
信息: updating User instance
2010-3-29 19:03:13 per.jsp.entity.EntityManagerHelper log
信息: update successful (它这里说successful,但我到数据库里去看数据并没有更新,为什么呢?用DAO的save也不能存入)
信息: finding all User instances
110 jsf_HelloWorldPU INFO [main] openjpa.Runtime - Starting OpenJPA 1.2.0
235 jsf_HelloWorldPU INFO [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.MySQLDictionary".
1031 jsf_HelloWorldPU INFO [main] openjpa.Enhance - Creating subclass for "[class per.jsp.entity.User]". This means that your application will be less efficient and will consume more memory than it would if you ran the OpenJPA enhancer. Additionally, lazy loading will not be available for one-to-one and many-to-one persistent attributes in types using field access; they will be loaded eagerly instead.
2010-3-29 19:03:13 per.jsp.entity.EntityManagerHelper log
信息: finding User instance with id: 1
2 (这两条是我打印出来的,即它能从数据库里取出来)
pcenshao
2010-3-29 19:03:13 per.jsp.entity.EntityManagerHelper log
信息: updating User instance
2010-3-29 19:03:13 per.jsp.entity.EntityManagerHelper log
信息: update successful (它这里说successful,但我到数据库里去看数据并没有更新,为什么呢?用DAO的save也不能存入)
解决方案 »
- MyBatis 取出insert的lastid
- 实体类做为Form属性
- Tomcat视频教程
- 上传文件解析为二进制流问题
- 问一个struts中的页面跳转问题
- java jsp用的求个 双击的 代码。。。
- 部署jar时出现的问题,问怎么解决(weblogic,jbuilder)
- jbuilder中为何不能正确显示JavaScript文件?急~~~~~~~
- 菜鸟问题!我在weblogic中配置连接池时出错!!急需解决!!!
- J2EE、EJB、JAVA BEANS都有些什么内容?
- 内部网中存在大量js脚本逻辑的企业应用如何安全地转移到公网上?
- Hibernate中get find load iteator 的区别与联系
其他代码都是myeclipse自动生成的
用的是annotation方块配的entity
UserDAO ud=new UserDAO();
System.out.println(ud.findAll().size()); // 结果:2
u=ud.findById(1);
System.out.println(u.getName()); //结果:pcenshao 都是我手动insert到数据库的
u.setName("aaaA");
ud.update(u);
}昨天晚上运行了好几次 今天打开mysql看数据 还是没有变呀...程序没有exception啊
import java.util.logging.Logger;import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
/**
* @author MyEclipse Persistence Tools
*/
public class EntityManagerHelper {
private static final EntityManagerFactory emf;
private static final ThreadLocal<EntityManager> threadLocal;
private static final Logger logger;
static {
emf = Persistence.createEntityManagerFactory("jsf_HelloWorldPU");
threadLocal = new ThreadLocal<EntityManager>();
logger = Logger.getLogger("jsf_HelloWorldPU");
logger.setLevel(Level.ALL);
}
public static EntityManager getEntityManager() {
EntityManager manager = threadLocal.get();
if (manager == null || !manager.isOpen()) {
manager = emf.createEntityManager();
threadLocal.set(manager);
}
return manager;
}
public static void closeEntityManager() {
EntityManager em = threadLocal.get();
threadLocal.set(null);
if (em != null) em.close();
}
public static void beginTransaction() {
getEntityManager().getTransaction().begin();
}
public static void commit() {
getEntityManager().getTransaction().commit();
}
public static void rollback() {
getEntityManager().getTransaction().rollback();
}
public static Query createQuery(String query) {
return getEntityManager().createQuery(query);
}
public static void log(String info, Level level, Throwable ex) {
logger.log(level, info, ex);
}
}
我不知道 我是直接调用dao的 dao是myeclipse直接生成的 应该没有问题吧 晚上回来看看
真的是没有commit 看来myeclipse生成的代码也不可信任了 我就以为在dao里有这样的操作了呀 哪想到它没有这一点不知道为什么了??
是有道理的 可以多个entity后才提交