- 浏览: 520934 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (88)
- Ant (4)
- Apache (2)
- chm (1)
- Javadoc api (7)
- Spring (9)
- Maven (7)
- Hibernate (4)
- Postgresql (1)
- Velocity (1)
- 有意思的题目 (3)
- Solr (4)
- eclipse (7)
- jpa (3)
- java (8)
- excel (1)
- jsp (1)
- ubuntu (2)
- 设计模式 (1)
- memcached (1)
- tomcat (4)
- Exception (2)
- 实用小技巧 (5)
- javascript (1)
- jquery (1)
- nginx (5)
- html (1)
- 一步一步升级配置 (8)
- windows (1)
- 注册表 (1)
- chrome (2)
- tiles (1)
- git (3)
- json (1)
- log (5)
- node.js (1)
- gradle (1)
- spring-session (5)
- mysql (1)
- ajax (1)
- dubbo (1)
- springmvc (1)
- loxia (1)
最新评论
-
akang_cdx:
JPEGImageEncoder encoder = JPEG ...
【飞天奔月出品】javax.imageio.IIOException: Can't create output stream!tomcat 验证码,图片(原理) -
飞天奔月:
zuxianghuang 写道解决问题了,谢谢不客气
Nginx SSL+tomcat集群,request.getScheme() 取到https正确的协议 -
zuxianghuang:
解决问题了,谢谢
Nginx SSL+tomcat集群,request.getScheme() 取到https正确的协议 -
飞天奔月:
加上了 jdk8 String.join性能不错
字符串拼接汇总(性能对比) -
fanlei77:
JDK8的String.join可以加一下一起比较
字符串拼接汇总(性能对比)
开箱即用(配置过程),使用spring 减少配置hibernate mapping 的痛苦(AnnotationSessionFactoryBean)
- 博客分类:
- Spring
今天在给公司新来的同事讲解项目架构的时候,项目中用到了JPA 正向生成数据库的技术,每新建一个pojo @entity,都需要在 hibernate.cfg.xml 增加一个 mapping
<mapping class="com.jumbo.model.system.MailSubscription"/>
有位同事就问,可不可以使用通配符,不用每次配一个,而且以前负责过Nike 商城的发布,经常发现开发工程师没有在项目发布模版文档里面,把新增的 mapping 写上,导致项目发布出现exception
要是真能做到,新增一个entity,删除一个entity,不用修改 hibernate.cfg.xml 就好了 ,
下面附上我实践的全过程,(要是不想看我废话的,直接拉到最后看我的配置)
晚上实践了下 ,
<mapping class="com.jumbo.model.*" />
走,启动
... 30 more
Caused by: org.hibernate.MappingException: Unable to load class declared as <mapping class="com.jumbo.model.*"/> in the configuration:
at org.hibernate.cfg.AnnotationConfiguration.parseMappingElement(AnnotationConfiguration.java:740)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1647)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1626)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:1224)
报错了,
网上搜搜,是不是我通配符配置错了,再来
<mapping class="com.jumbo.model.**.*" />
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 76 more Caused by: java.lang.ClassNotFoundException: com.jumbo.model.**.* at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1361) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169)
哥杯具了
看了下dtd,貌似 mapping还有其他属性(package),试试
<mapping package="com.jumbo.model" />
走,启动,日志里面只有这么一句
19:46:24,177 INFO [Configuration] configuring from url: file:/E:/Workspaces/baozun/usercenter/usercenter-frontend/src/main/webapp/WEB-INF/classes/hibernate.cfg.xml
19:46:24,364 INFO [AnnotationConfiguration] Mapping package com.jumbo.model
19:46:24,599 INFO [Configuration] Configured SessionFactory: null
但是没有以前见到的 表和 entity 一一对应的效果,貌似没有成功,表(member)里面增加个字段(test)试试
/*************************************************************************************/ private String test; /** PK */ private Long id;
setter,getter 方法
启动,去数据库看看,表没有新增我刚加的test 字段,看来是配置不成功,
去看看 package到底是做什么的,以前没有接触过,接触过最多的就是 反向工程的 resource(xml 配置),以及正向工程的 class(annotition配置),
网上还找不到具体的介绍,都说这个package 没用
哥心说,”没用的话,hibernate 设置这个值干嘛吃的?” 继续找,终于 在 http://www.jetbrains.net/jira/browse/HBR-4 文档里面 ,发现有牛人回复了
This is not a problem or shortcoming of Hibero.
To specify mapping entities using annotations use the tag <mapping class="fqclassname"/>.
啊,原来 package 用在 package 注释级别的
看来我的用法是错的,但是我的entity 总不能去改吧,(再说 这个package 到底怎么用,还不清楚撒)想想有没有其他的办法,
活人怎么能给尿憋死, 国内国外像我这么懒的人肯定有(不想手写那么多的mapping啊 ),
找找资料 ,果然有”前辈”, http://stackoverflow.com/questions/1413190/hibernate-mapping-package
娃哈哈,spring 的AnnotationSessionFactoryBean 有自动扫描(packagesToScan)的功能 ,尝试着用用看
不过 我们的sessionFactory bean 被我们的架构师封装在 loxia jar 里面
那么我就重写一个
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation"> <value>classpath:hibernate.cfg.xml</value> </property> <property name="packagesToScan" value="com.jumbo.model" /> </bean>
启动的时候 会自动replace
看日志
18:20:16,095 INFO [DefaultListableBeanFactory]
Overriding bean definition for bean 'sessionFactory': replacing [Generic bean: class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null;
defined in URL [file:/E:/Workspaces/baozun/usercenter/usercenter-frontend/src/main/webapp/WEB-INF/classes/spring.xml]] with [Generic bean:
class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null;
defined in URL [jar:file:/E:/Workspaces/baozun/usercenter/usercenter-frontend/src/main/webapp/WEB-INF/lib/loxia2-core-2.5.jar!/loxia-hibernate-context.xml]]
我的 hibernate配置文件里面 , 还有named query
<mapping resource="META-INF/orm-master.xml" /> <mapping resource="META-INF/orm-member.xml" /> <mapping resource="META-INF/orm-sales.xml" /> <mapping resource="META-INF/orm-system.xml" />
研究加实验下 ,发现了 mappingDirectoryLocations,心想要是只配个 文件夹 META-INF,自动扫描出 下面的orm-*.xml 世界都美妙阿
go,尝试下
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:hibernate.cfg.xml" /> <property name="packagesToScan"> <list> <value>com.jumbo.model</value> </list> </property> <property name="mappingDirectoryLocations"> <list> <value>/META-INF</value> </list> </property> </bean>
发现没有起作用, 敏思苦想,文件夹式配置都不成功
只有去看看源码,一路debug,发现了 hiberntae 这么个method
public Configuration addDirectory(File dir) throws MappingException { File[] files = dir.listFiles(); for ( int i = 0; i < files.length ; i++ ) { if ( files[i].isDirectory() ) { addDirectory( files[i] ); } else if ( files[i].getName().endsWith( ".hbm.xml" ) ) { addFile( files[i] ); } } return this; }
噢,原来 文件名必须.hbm.xml 结尾才加如到 Configuration, .hbm.xml一般都是配置映射关系的,我的只是namedquery 文件 ,那么 mappingDirectoryLocations这东东我们就用不了,再看看 有没有其他的配置方式
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:hibernate.cfg.xml" /> <property name="packagesToScan"> <list> <value>com.jumbo.model</value> </list> </property> <property name="mappingLocations"> <list> <value>/META-INF/orm-*.xml</value> </list> </property> </bean>
这个可以读取到 配置的namedquery了 ,查看源码
@Override public void add(org.dom4j.Document doc) throws MappingException { boolean ejb3Xml = "entity-mappings".equals( doc.getRootElement().getName() ); if ( inSecondPass ) { //if in second pass bypass the queueing, getExtendedQueue reuse this method if ( !ejb3Xml ) { super.add( doc ); } } else { if ( !ejb3Xml ) { final Element hmNode = doc.getRootElement(); Attribute packNode = hmNode.attribute( "package" ); String defaultPackage = packNode != null ? packNode.getValue() : ""; Set<String> entityNames = new HashSet<String>(); findClassNames( defaultPackage, hmNode, entityNames ); for ( String entity : entityNames ) { hbmEntities.put( entity, doc ); } hbmDocuments.add( doc ); } else { final MetadataProvider metadataProvider = ( ( MetadataProviderInjector ) reflectionManager ).getMetadataProvider(); JPAMetadataProvider jpaMetadataProvider = ( JPAMetadataProvider ) metadataProvider; List<String> classnames = jpaMetadataProvider.getXMLContext().addDocument( doc ); for ( String classname : classnames ) { try { annotatedClasses.add( reflectionManager.classForName( classname, this.getClass() ) ); } catch ( ClassNotFoundException e ) { throw new AnnotationException( "Unable to load class defined in XML: " + classname, e ); } } } } }
恩,是以InputStream 的形式,xml root element 是 entity-mappings文件 ,yes 是我要的 东东 ,
这么配置,我们看看log,是不是和以前差不多
15:23:55,216 INFO [Environment] Hibernate 3.5.6-Final 15:23:55,221 INFO [Environment] hibernate.properties not found 15:23:55,231 INFO [Environment] Bytecode provider name : javassist 15:23:55,237 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling 15:23:55,350 INFO [Version] Hibernate Commons Annotations 3.2.0.Final 15:23:55,367 INFO [Configuration] configuring from url: file:/E:/Workspaces/baozun/usercenter/usercenter-frontend/src/main/webapp/WEB-INF/classes/hibernate.cfg.xml 15:23:55,426 INFO [Configuration] Configured SessionFactory: null 15:28:37,410 INFO [QueryBinder] Binding Named query: Product.findProductByCode => select product from Product as product where product.code = :code 15:28:37,413 INFO [QueryBinder] Binding Named query: Sku.findSkuByCode => select sku from Sku as sku where sku.code = :code 15:28:37,418 INFO [QueryBinder] Binding Named query: Member.findMemberByAccountAndRegSource => select m from Member as m where m.account = :account and m.regSource = :regSource 15:28:37,421 INFO [QueryBinder] Binding Named query: Rank.findRankByCode => select rank from Rank as rank where rank.code = :code 15:28:37,424 INFO [QueryBinder] Binding Named query: MemberAddress.findListByMember => select ma from MemberAddress as ma where ma.member.id = :memberId order by ma.isDefault desc,ma.id 15:28:37,428 INFO [QueryBinder] Binding Named query: MemberLoginLog.getLastLoginLogTime => select loginLog.loginTime from MemberLoginLog as loginLog where loginLog.memberId = :memberId and loginLog.loginStatus= com.jumbo.model.system.LoginStatus.LOGIN_SUCCESS order by loginLog.loginTime desc limit 1; 15:28:37,431 INFO [QueryBinder] Binding Named query: MemberRank.findMemberRankByMemberIdAndRankTypeId => select memberRank from MemberRank as memberRank where memberRank.member.id=:memberId and memberRank.rankType.id=:rankTypeId 15:28:37,434 INFO [QueryBinder] Binding Named query: MemberRank.findMemberRankByMemberIdAndRankTypeCode => select memberRank from MemberRank as memberRank where memberRank.member.id=:memberId and memberRank.rankType.code=:rankTypeCode 15:28:37,437 INFO [QueryBinder] Binding Named query: Rank.findRankByTotalRankConsumption => select rank from Rank as rank where rank.rankType.code =com.jumbo.model.member.RankType.code_ByTotalConsumption and rank.condition <=:totalRankConsumption order by rank.condition desc 15:28:37,442 INFO [QueryBinder] Binding Named query: PointRule.findPointRuleByCode => select pointRule from PointRule as pointRule where pointRule.code =:code 15:28:37,444 INFO [QueryBinder] Binding Named query: ReturnApplication.findReturnApplicationByCode => select ra from ReturnApplication as ra where ra.code = :code 15:28:37,447 INFO [QueryBinder] Binding Named query: ReturnApplicationLine.findReturnApplicationLineByRefId => select ral from ReturnApplicationLine as ral where ral.refId = :refId 15:28:37,452 INFO [QueryBinder] Binding Named query: ReturnOrder.findReturnOrderByCode => select ro from ReturnOrder as ro where ro.code = :code 15:28:37,454 INFO [QueryBinder] Binding Named query: RoLine.findRoLineByRefId => select rol from RoLine as rol where rol.refId = :refId 15:28:37,457 INFO [QueryBinder] Binding Named query: SalesOrder.getSalesOrderList => select so from SalesOrder as so where so.platfrom = :platfrom and so.userName=:userName 15:28:37,460 INFO [QueryBinder] Binding Named query: SalesOrder.findSalesOrderByCode => select so from SalesOrder as so where so.code = :code 15:28:37,464 INFO [QueryBinder] Binding Named query: SoLine.findSalesOrderLineByRefId => select sol from SoLine as sol where sol.refId = :refId 15:28:37,467 INFO [QueryBinder] Binding Named query: ReturnOrderLog.findReturnOrderLogList => select rol from ReturnOrderLog as rol where rol.salesOrder.id = :soId 15:28:37,469 INFO [QueryBinder] Binding Named query: ApiClient.findApiClientByIdAndSecret => select client from ApiClient as client where client.clientId=:clientId and client.clientSecret=:clientSecret 15:28:37,474 INFO [QueryBinder] Binding Named query: ApiTask.findResultByClient => select task from ApiTask as task where task.clientId=:clientId and task.taskId=:taskId 15:28:37,476 INFO [QueryBinder] Binding Named query: ChooseOption.findOptionListByCategoryCode => select o from ChooseOption as o where o.categoryCode = :categoryCode and o.isAvailable = true order by o.sortNo 15:28:37,479 INFO [QueryBinder] Binding Named query: ChooseOption.findAllOptionListByCategoryCode => select o from ChooseOption as o where o.categoryCode = :categoryCode order by o.sortNo 15:28:37,482 INFO [QueryBinder] Binding Named query: ChooseOption.findByCategoryCodeAndKey => select o from ChooseOption as o where o.categoryCode = :categoryCode and o.optionKey = :key 15:28:37,486 INFO [QueryBinder] Binding Named query: Bulletin.findBulletinList => select o from Bulletin as o where o.status = :status and o.effectiveTime <= :effectiveTime 15:28:37,489 INFO [QueryBinder] Binding Named query: MailSubscription.findByEMail => select m from MailSubscription as m where m.email = :email 15:28:37,501 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.master.CategoryPropertyName 15:28:37,619 INFO [EntityBinder] Bind entity com.jumbo.model.master.CategoryPropertyName on table T_MA_CAT_PRO_NAME 15:28:37,676 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.master.Product 15:28:37,681 INFO [EntityBinder] Bind entity com.jumbo.model.master.Product on table T_MA_PRODUCT 15:28:37,690 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.master.ProductCategory 15:28:37,692 INFO [EntityBinder] Bind entity com.jumbo.model.master.ProductCategory on table T_MA_PRO_CAT 15:28:37,703 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.master.Sku 15:28:37,706 INFO [EntityBinder] Bind entity com.jumbo.model.master.Sku on table T_MA_SKU 15:28:37,713 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.master.SkuDynamicProperty 15:28:37,718 INFO [EntityBinder] Bind entity com.jumbo.model.master.SkuDynamicProperty on table T_MA_SKU_DYN 15:28:37,726 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.member.Area 15:28:37,728 INFO [EntityBinder] Bind entity com.jumbo.model.member.Area on table T_MA_AREA 15:28:37,733 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.member.Member 15:28:37,737 INFO [EntityBinder] Bind entity com.jumbo.model.member.Member on table T_MA_MEMBER 15:28:37,777 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.member.MemberAddress 15:28:37,782 INFO [EntityBinder] Bind entity com.jumbo.model.member.MemberAddress on table T_MA_MEMBER_ADDRESS 15:28:37,792 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.member.MemberRank 15:28:37,795 INFO [EntityBinder] Bind entity com.jumbo.model.member.MemberRank on table T_MA_MEMBER_RANK 15:28:37,806 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.member.PointRule 15:28:37,809 INFO [EntityBinder] Bind entity com.jumbo.model.member.PointRule on table T_MA_POINTRULE 15:28:37,814 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.member.Rank 15:28:37,816 INFO [EntityBinder] Bind entity com.jumbo.model.member.Rank on table T_MA_RANK 15:28:37,827 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.member.RankType 15:28:37,830 INFO [EntityBinder] Bind entity com.jumbo.model.member.RankType on table T_MA_RANKTYPE 15:28:37,834 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.misc.Bulletin 15:28:37,839 INFO [EntityBinder] Bind entity com.jumbo.model.misc.Bulletin on table t_misc_bulletin 15:28:37,884 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.sales.ReturnApplication 15:28:37,888 INFO [EntityBinder] Bind entity com.jumbo.model.sales.ReturnApplication on table T_SO_RETURN_REQUEST 15:28:37,901 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.sales.ReturnApplicationLine 15:28:37,904 INFO [EntityBinder] Bind entity com.jumbo.model.sales.ReturnApplicationLine on table T_SO_RETURN_REQUEST_LINE 15:28:37,918 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.sales.ReturnOrder 15:28:37,921 INFO [EntityBinder] Bind entity com.jumbo.model.sales.ReturnOrder on table T_SO_RETURN_ORDER 15:28:37,930 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.sales.RoLine 15:28:37,935 INFO [EntityBinder] Bind entity com.jumbo.model.sales.RoLine on table T_SO_RETURN_ORDER_LINE 15:28:37,945 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.sales.SalesOrder 15:28:37,948 INFO [EntityBinder] Bind entity com.jumbo.model.sales.SalesOrder on table T_SO_SALES_ORDER 15:28:37,969 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.sales.SoLine 15:28:37,971 INFO [EntityBinder] Bind entity com.jumbo.model.sales.SoLine on table T_SO_SO_LINE 15:28:37,977 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.sales.SoMember 15:28:37,980 INFO [EntityBinder] Bind entity com.jumbo.model.sales.SoMember on table T_SO_SO_MEMBER 15:28:37,992 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.system.ApiClient 15:28:37,995 INFO [EntityBinder] Bind entity com.jumbo.model.system.ApiClient on table T_SYS_API_CLIENT 15:28:37,999 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.system.ApiTask 15:28:38,004 INFO [EntityBinder] Bind entity com.jumbo.model.system.ApiTask on table T_SYS_API_TASK 15:28:38,011 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.system.authorization.OperationUnit 15:28:38,014 INFO [EntityBinder] Bind entity com.jumbo.model.system.authorization.OperationUnit on table T_AU_OPERATION_UNIT 15:28:38,025 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.system.authorization.OperationUnitType 15:28:38,028 INFO [EntityBinder] Bind entity com.jumbo.model.system.authorization.OperationUnitType on table T_AU_OPERATION_UNIT_TYPE 15:28:38,033 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.system.authorization.Privilege 15:28:38,036 INFO [EntityBinder] Bind entity com.jumbo.model.system.authorization.Privilege on table T_AU_PRIVILEGE 15:28:38,047 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.system.authorization.Role 15:28:38,050 INFO [EntityBinder] Bind entity com.jumbo.model.system.authorization.Role on table T_AU_ROLE 15:28:38,057 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.system.authorization.User 15:28:38,062 INFO [EntityBinder] Bind entity com.jumbo.model.system.authorization.User on table T_AU_USER 15:28:38,071 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.system.authorization.UserGroup 15:28:38,074 INFO [EntityBinder] Bind entity com.jumbo.model.system.authorization.UserGroup on table T_AU_USER_GROUP 15:28:38,083 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.system.authorization.UserGroupRelation 15:28:38,086 INFO [EntityBinder] Bind entity com.jumbo.model.system.authorization.UserGroupRelation on table T_AU_USER_GROUP_RELATION 15:28:38,090 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.system.authorization.UserRole 15:28:38,092 INFO [EntityBinder] Bind entity com.jumbo.model.system.authorization.UserRole on table T_AU_USER_ROLE 15:28:38,102 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.system.ChooseOption 15:28:38,105 INFO [EntityBinder] Bind entity com.jumbo.model.system.ChooseOption on table T_SYS_CHOOSE_OPTION 15:28:38,109 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.system.MailSubscription 15:28:38,114 INFO [EntityBinder] Bind entity com.jumbo.model.system.MailSubscription on table T_SYS_MAIL_SUBSCRIPTION 15:28:38,122 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.system.MemberLoginLog 15:28:38,125 INFO [EntityBinder] Bind entity com.jumbo.model.system.MemberLoginLog on table T_SYS_MEM_LOGIN_LOG 15:28:38,139 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.system.MemberMessage 15:28:38,142 INFO [EntityBinder] Bind entity com.jumbo.model.system.MemberMessage on table T_SYS_MEMBER_MSG 15:28:38,146 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.system.MemberPointLog 15:28:38,149 INFO [EntityBinder] Bind entity com.jumbo.model.system.MemberPointLog on table T_SYS_MEMBER_POINT_LOG 15:28:38,159 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.system.MemberRankLog 15:28:38,162 INFO [EntityBinder] Bind entity com.jumbo.model.system.MemberRankLog on table T_SYS_MEMBER_RANK_LOG 15:28:38,168 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.system.ReturnOrderLog 15:28:38,172 INFO [EntityBinder] Bind entity com.jumbo.model.system.ReturnOrderLog on table T_SYS_RETURN_ORDER_LOG 15:28:38,180 INFO [AnnotationBinder] Binding entity from annotated class: com.jumbo.model.system.SystemMessage 15:28:38,183 INFO [EntityBinder] Bind entity com.jumbo.model.system.SystemMessage on table T_SYS_MESSAGE 15:28:38,222 INFO [CollectionBinder] Mapping collection: com.jumbo.model.member.Member.memberAddresses -> T_MA_MEMBER_ADDRESS 15:28:38,225 INFO [CollectionBinder] Mapping collection: com.jumbo.model.member.Member.memberRanks -> T_MA_MEMBER_RANK 15:28:38,228 INFO [CollectionBinder] Mapping collection: com.jumbo.model.sales.ReturnApplication.appLines -> T_SO_RETURN_REQUEST_LINE 15:28:38,234 INFO [CollectionBinder] Mapping collection: com.jumbo.model.sales.ReturnOrder.roLines -> T_SO_RETURN_ORDER_LINE 15:28:38,236 INFO [CollectionBinder] Mapping collection: com.jumbo.model.sales.SalesOrder.soLines -> T_SO_SO_LINE 15:28:38,239 INFO [CollectionBinder] Mapping collection: com.jumbo.model.system.authorization.OperationUnit.childrenUnits -> T_AU_OPERATION_UNIT 15:28:38,244 INFO [CollectionBinder] Mapping collection: com.jumbo.model.system.authorization.OperationUnitType.ous -> T_AU_OPERATION_UNIT 15:28:38,254 INFO [AnnotationConfiguration] Hibernate Validator not found: ignoring
yes,没错
好了, hibernate.cfg.xml里面 就留下自己的参数配置
<session-factory>
<property name="show_sql">false</property> <property name="format_sql">false</property> <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property> <property name="hibernate.query.substitutions">true 1, false 0, yes 'Y', no 'N'</property> <property name="hibernate.jdbc.batch_size">100</property> </session-factory> </hibernate-configuration>
spring.xml 里面 配置
<!--over write sessionFactory in loxia-hibernate-context.xml--> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:hibernate.cfg.xml" /> <property name="packagesToScan"> <list> <value>com.jumbo.model</value> </list> </property> <property name="mappingLocations"> <list> <value>/META-INF/orm-*.xml</value> </list> </property> </bean>
就可以把所有原来写在 hibernate.cfg.xml 里面的 mapping 给干掉了 ,以后没新增或者删除一个@entity,不用去动hibernate.cfg.xml
附加一句 , hibernate.cfg.xml 关于hibernate的参数也可以在 spring 里面配置,但是 个人认为这部分的参数,仍然在hibernate 里面 配置比较好,反正在spring 里面配置这些参数也得写这么多代码
最后,附上一个 我查询源码过程中的 一个 脑图 给大家参考下
参考资料:http://stackoverflow.com/questions/1413190/hibernate-mapping-package
评论
发表评论
-
当商品编码遇到了.号, spring restful @PathVariable 应对措施
2018-07-09 17:36 17001. 背景 今天我们的某 ... -
【飞天奔月出品】一步一步升级配置13: 将tiles 升级到3.0.1 (spring集成tiles指南)
2013-07-16 01:29 3809tiles 是一个 模板框架.目的是为了简化前端用户界面的 ... -
一步一步升级配置7:开发环境使用maven tomcat plugin 来运行项目,大幅度提到开发效率
2012-08-31 17:00 4428背景: 目前官方商 ... -
一步一步升级spring配置5:使用P标签及内部bean简化spring quartz配置
2012-06-28 11:22 44961.原始做法: spring quartz配置文件,一 ... -
一步一步升级spring配置4:使用SPEL和Util标签配置spring xml参数
2012-05-26 16:06 46821.原始做法: spring xml配置文件,参数直接 ... -
使用springmvc 发布rss
2012-03-05 01:59 2025很喜欢google阅读器,一直就像写个自己的rss玩玩,碰巧这 ... -
升级到hibernate search 4.0,hibernate core4 ,spring 3.1 初步代码变化
2011-12-26 20:00 50491.hibernate search 已经有4.0.0. ... -
<mvc:annotation-driven>和DefaultAnnotationHandlerMapping 配置教训
2011-11-21 22:34 19627前一阵子,负责公司用户中心项目的开发,发现了spring新版本 ...
相关推荐
《图书管理系统spring+struts+hibernate》是一款基于Java技术栈开发的图书管理软件,其核心框架包括Spring、Struts和Hibernate。该系统利用MySQL作为数据库存储数据,提供了完整的数据库备份,确保了数据的安全性与...
Spring集成JPA(Java Persistence API)是将Spring框架与ORM(Object-Relational Mapping)解决方案之一的Hibernate结合使用的常见实践。这个例子展示了如何在Spring应用中配置和使用JPA,以便利用Hibernate作为JPA...
1. **Spring ORM**:Spring框架提供了一组ORM(Object-Relational Mapping)支持服务,其中包括对Hibernate的支持。这些支持服务简化了数据库访问,并且使得与不同的ORM工具进行集成变得更加容易。 2. **Hibernate...
在IT行业中,Spring、SpringMVC和Hibernate是三个非常重要的Java开发框架,它们共同构建了SSH(Spring、SpringMVC、Hibernate)体系,为开发者提供了高效、灵活的Web应用程序开发解决方案。下面将详细介绍这三个框架...
在Spring的配置文件中,我们可以使用Hibernate的Template或DAO来处理数据库操作。例如,创建一个HibernateTemplate Bean: ```xml <bean id="hibernateTemplate" class="org.springframework.orm.hibernate5....
这个压缩包文件的标题和描述表明,它包含了使用Spring 3.0、SpringMVC 3.0和Hibernate 3.0进行注解编码的相关内容,特别是关于控制器层(Controller)、服务层(Service)和数据访问对象层(DAO)的注解实践。...
因为Hibernate在读出hbm.xml文件时需要通过网络读取到hibernate-mapping-3.0.dtd 文件。 如果没有网络不能正常工作。 所以提供上述文件。 以及hibernate-mapping-3.0.dtd,hibernate-configuration-3.0.dtd提供下载...
Hibernate3.3则是一个持久层框架,它简化了数据库操作,通过ORM(Object-Relational Mapping,对象关系映射)技术将Java对象与数据库表对应起来,使得开发者可以使用面向对象的方式进行数据库操作。Hibernate3.3引入...
【标题】"spring+springMVC+hibernate"整合应用详解 【描述】在现代企业级Java开发中,Spring、SpringMVC和Hibernate是三个非常重要的框架,它们的组合通常被称为SSH(Spring、SpringMVC、Hibernate)三位一体的...
3. 配置Hibernate:在Spring配置中集成Hibernate,配置SessionFactory、DataSource等,还可以使用Spring的TransactionManager进行事务管理。 4. 创建DAO层:使用Spring的JdbcTemplate或Hibernate的Session接口进行...
SSH整合的关键在于配置,主要包括Spring的配置文件(如`applicationContext.xml`)、SpringMVC的配置文件(如`servlet-context.xml`)以及Hibernate的配置文件(如`hibernate.cfg.xml`)。在整合过程中,Spring会...
本文将详细解析 `hibernate-mapping` 文件中的各种关键配置项及其含义。 #### 1. default-access (可选 - 默认为 property) 此属性用于指定 Hibernate 访问实体类属性的方式,默认为通过 getter 和 setter 方法...
图文教程MyEclipse配置struts+hibernate+spring.doc 本文档主要讲述了如何在MyEclipse中配置struts、hibernate和spring三个框架,以实现一个完整的Web应用程序。下面是从本文档中提取的重要知识点: 1.struts框架...
例如,Spring的配置文件(如`applicationContext.xml`)会定义bean的定义和依赖关系,SpringMVC的配置文件(如`servlet-context.xml`)会配置URL映射和视图解析器,而Hibernate的配置文件(如`hibernate.cfg.xml`)...
Hibernate通过ORM(Object-Relational Mapping)技术将Java对象映射到数据库表,减少了SQL的编写工作,提高了开发效率。它还提供了缓存机制、事务管理和查询语言HQL,使得数据库操作更加高效和便捷。 将Spring、...
SSH框架,全称为Struts2、Spring和Hibernate的组合,是一种流行的企业级Java Web应用程序开发框架。这个框架的集成能够帮助开发者实现模型-视图-控制器(MVC)设计模式,提供数据持久化,以及应用层的管理和依赖注入...
Spring、SpringMVC和Hibernate是Java开发中常用的三大框架,它们各自负责应用程序的不同层面:Spring作为基础框架,SpringMVC处理Web层逻辑,而Hibernate则专注于数据持久化。本项目是一个将这三个框架整合的示例,...
随着技术的发展,Spring Boot和Spring MVC的崛起,SSH整合逐渐被Spring全家桶所替代,因为Spring Boot的开箱即用和自动化配置极大地简化了开发流程。不过,了解SSH整合对于理解现代Java Web开发的历史和发展仍有重要...