hibernate泛型DAO

泛型DAO(翻译)

http://www.iteye.com/topic/151090 

泛型Dao--以上面代码的分析

http://littie1987.iteye.com/blog/1023573

基于泛型DAO的Facade设计模式.

http://www.iteye.com/topic/403182

spring mvc 系列2 泛型DAO(基于存储过程)

http://www.iteye.com/topic/777732

Hibernate 二级缓存 收集、总结整理 

http://jinnianshilongnian.iteye.com/blog/1525884

Hibernate的三种连接池设置C3P0、Proxool和DBCP

http://www.blogjava.net/xzclog/archive/2010/01/30/311319.html

SpringMVC + spring3.1.1 + hibernate4.1.0 集成及常见问题总结

http://jinnianshilongnian.iteye.com/blog/1423971

Spring Hibernate 通用泛型处理

http://gznofeng.iteye.com/blog/228835

Spring+Hibernate的泛型DAO类

http://xmkevinchen.iteye.com/blog/485403

展开阅读全文

Hibernat泛型DAO问题

04-27

在程序中使用springside的DAO,使用级联时候出现问题rnrn[code="java"]rnrnpublic class SimpleHibernateDao rnrn protected Logger logger = LoggerFactory.getLogger(getClass());rnrn protected SessionFactory sessionFactory;rnrn protected Class entityClass;rnrn /**rn * 用于扩展的DAO子类使用的构造函数.rn * rn * 通过子类的泛型定义取得对象类型Class.rn * eg.rn * public class UserDao extends SimpleHibernateDaorn */rn public SimpleHibernateDao() rn this.entityClass = ReflectionUtils.getSuperClassGenricType(getClass());rn rnrn /**rn * 用于Service层直接使用SimpleHibernateDAO的构造函数.rn * eg.rn * SimpleHibernateDao userDao = new SimpleHibernateDao(sessionFactory, User.class);rn */rn public SimpleHibernateDao(final SessionFactory sessionFactory, final Class entityClass) rn this.sessionFactory = sessionFactory;rn this.entityClass = entityClass;rn rnrn public SessionFactory getSessionFactory() rn return sessionFactory;rn rnrn///................其他省略rnrnrnrnrn[code="java"]rnpublic class HibernateDao extends SimpleHibernateDao rn /**rn * 用于扩展的DAO子类使用的构造函数.rn * rn * 通过子类的泛型定义取得对象类型Class.rn * eg.rn * public class UserDao extends HibernateDaorn * rn */rn public HibernateDao() rn super();rn rnrn /**rn * 用于Service层直接使用HibernateDAO的构造函数.rn * eg.rn * HibernateDao userDao = new HibernateDao(sessionFactory, User.class);rn */rn public HibernateDao(final SessionFactory sessionFactory, final Class entityClass) rn super(sessionFactory, entityClass);rn rnrn // 分页查询函数 //rnrn /**rn * 分页获取全部对象. rn */rn public Page getAll(final Page page) rn return findByCriteria(page);rn rn//其他rnrnrn下面是实体rn[/code]rnrn[code="java"]rnrn@Entityrn@Table(name = "WFPROCESSINST", schema = "TSSA")rn@Proxy(lazy=false)rnpublic class Wfprocessinst implements java.io.Serializable rnprivate BigDecimal processinstid;rn@Idrn @Column(name = "PROCESSINSTID", unique = true, nullable = false, precision = 22, scale = 0)rn public BigDecimal getProcessinstid() rn return this.processinstid;rn rnrn public void setProcessinstid(BigDecimal processinstid) rn this.processinstid = processinstid;rn rn private String processinstname;rn private Set wftransitions = new HashSet(0);rn @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "wfprocessinst")rn public Set getWfactivityinsts() rn return this.wfactivityinsts;rn rnrn public void setWfactivityinsts(Set wfactivityinsts) rn this.wfactivityinsts = wfactivityinsts;rn rnrnrn[/code]rnrnrn当fetch = FetchType.EAGER 报错,为FetchType.LAZY 正常。rnrnrn异常rnrnrn[WARN ]2009-04-27 16:26:57,868 org.hibernate.util.JDBCExceptionReporter SQL Error: 17027, SQLState: nullrn[ERROR]2009-04-27 16:26:57,868 org.hibernate.util.JDBCExceptionReporter 流已被关闭rn[INFO ]2009-04-27 16:26:57,870 org.hibernate.event.def.DefaultLoadEventListener Error performing load commandrnorg.hibernate.exception.GenericJDBCException: could not load an entity: [cn.com.starit.orm.hibernate.dojo.Wfprocessinst#8809358]rn at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)rn at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)rn at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)rn at org.hibernate.loader.Loader.loadEntity(Loader.java:1874)rn at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)rn at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)rn at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3044)rn at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:395)rn at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)rn at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)rn at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:179)rn at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)rn at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)rn at org.hibernate.impl.SessionImpl.load(SessionImpl.java:795)rn at org.hibernate.impl.SessionImpl.load(SessionImpl.java:788)rn at cn.com.starit.orm.hibernate.SimpleHibernateDao.get(SimpleHibernateDao.java:114)rn at cn.com.starit.orm.hibernate.EntityManager.get(EntityManager.java:38)rn at cn.com.starit.orm.hibernate.EntityManager$$FastClassByCGLIB$$7a912d89.invoke()rn at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)rn at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)rn at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)rn at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)rn at cn.com.starit.service.WFManager$$EnhancerByCGLIB$$e9c4798f.get()rn at cn.com.starit.action.UserAction.main(UserAction.java:21)rnCaused by: java.sql.SQLException: 流已被关闭rn at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)rn at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)rn at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)rn at oracle.jdbc.driver.LongAccessor.getBytes(LongAccessor.java:151)rn at oracle.jdbc.driver.LongAccessor.getString(LongAccessor.java:193)rn at oracle.jdbc.driver.T4CLongAccessor.getString(T4CLongAccessor.java:422)rn at oracle.jdbc.driver.OracleResultSetImpl.getString(OracleResultSetImpl.java:397)rn at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:1515)rn at org.hibernate.type.StringType.get(StringType.java:18)rn at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)rn at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)rn at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)rn at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2096)rn at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1380)rn at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1308)rn at org.hibernate.loader.Loader.getRow(Loader.java:1206)rn at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)rn at org.hibernate.loader.Loader.doQuery(Loader.java:701)rn at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)rn at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)n[b]问题补充:[/b]n代码被我没有有发完,是有的。n[b]问题补充:[/b]n级联查询rnApplicationContext context = new ClassPathXmlApplicationContext(rn "classpath:config/ApplicationContext.xml");rn WFManager wf = (WFManager) context.getBean("WFManager");rn Wfprocessinst dd;rn try rn dd= wf.get(new BigDecimal(8809358));rn System.out.println(dd.getProcessinstname());rn //Iterator ac= dd.getWfactivityinsts().iterator();rn// while(ac.hasNext())rn// System.out.println(ac.next().getActivityinstname());rn// rn// rn catch (Exception e) rn e.printStackTrace();rn rn System.out.println("this is a test");rn注释那一部分有问题n[b]问题补充:[/b]n我做了一个简单例子,还是错的,控制台输出的SQL是正确的n[b]问题补充:[/b]n是的哦,搞半天来了,没有搞定。rnrn输出的SQL是正常的。rn不是为什么哦?n[b]问题补充:[/b]n我用list试试n[b]问题补充:[/b]n怎么个用法,发端代码看看。n[b]问题补充:[/b]n还是不知道怎么解决哦?n[b]问题补充:[/b]n我先试试,问题先不关闭 问答

spring DAO泛型依赖注入

11-11

java.lang.IllegalStateException: Autowired annotation requires at least one argument: public void com.strogit.assetsmanagement.service.impl.AlarmServiceImpl.setAlarmDao()rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$2.doWith(AutowiredAnnotationBeanPostProcessor.java:307)rn at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:466)rn at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:443)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.findAutowiringMetadata(AutowiredAnnotationBeanPostProcessor.java:299)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(AutowiredAnnotationBeanPostProcessor.java:179)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:745)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:448)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)rn at java.security.AccessController.doPrivileged(Native Method)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)rn at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)rn at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)rn at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)rn at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)rn at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)rn at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)rn at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)rn at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.jrnrn怎么会出现这样的问题rnrnrn public BaseDAOImpl alarmDao;rn rn @Autowiredrn public void setAlarmDao() rn alarmDao=new BaseDAOImpl(Alarm.class);rn rnrn用的是注解配置rn 论坛

没有更多推荐了,返回首页