在使用Spring 3 + Hibernate JPA时发现JPA注释类(Discover JPA annotated classes when using Spring 3+Hibernate JPA)
我有一个使用Spring 3 + Hibernate JPA堆栈的Web应用程序。
我想知道是否有办法让Hibernate自动发现@Entity带注释的类,这样我就不必在persistence.xml文件中列出它们。 我的@Entity注释类“活着”在位于我的Web应用程序的WEB-INF / lib中的单独的jar中。
这是我的Spring配置文件中的一个片段:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceUnitName" value="mypersistence"/> <property name="dataSource" ref="dataSource"/> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="true"/> <property name="generateDdl" value="true"/> <property name="databasePlatform" value="org.hibernate.dialect.DerbyDialect"/> </bean> </property> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver"/> <property name="url" value="jdbc:derby://localhost:1527/library;create=true"/> <property name="username" value="app"/> <property name="password" value="app"/> </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> <bean id="persistenceAnnotation" class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
I have a web application using the Spring 3 + Hibernate JPA stack.
I would like to know if there is a way to have Hibernate to automatically discover @Entity annotated classes, so that I don't have to list them in the persistence.xml file. My @Entity annotated classes "live" in a separate jar, located in the WEB-INF/lib of my web application.
This is a snippet from my Spring configuration file:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceUnitName" value="mypersistence"/> <property name="dataSource" ref="dataSource"/> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="true"/> <property name="generateDdl" value="true"/> <property name="databasePlatform" value="org.hibernate.dialect.DerbyDialect"/> </bean> </property> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver"/> <property name="url" value="jdbc:derby://localhost:1527/library;create=true"/> <property name="username" value="app"/> <property name="password" value="app"/> </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> <bean id="persistenceAnnotation" class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
原文:https://stackoverflow.com/questions/4872705
满意答案
我不确定你是否看到他们,但仔细看看这些引号:
[1,'1','3/03/2011', [“ScrewDriver”, “Hammer”, “Stone”]]
这是有区别的:
”
和这个:
"
第一个(
”
)是一个引用解释器的引用。 使用普通引号("
)并回传你的脚本返回的内容。另外,这个
return
语句做了什么:return (new)
如果你在函数中,函数会在列表的第一次迭代时退出,因为它会在每一个循环中
return
,但是只有第一个被捕获并且函数在那里死掉。我将
return
语句向下移动一级,所以它不是for
循环的一部分。 所以改变这个:for line in lines: listline=eval(line) if not(num_del==list_line[0]): new +=(line + "\n") return (new)
为此:
for line in lines: listline=eval(line) if not(num_del==list_line[0]): new +=(line + "\n") return (new)
这是没有引号的文本文件。 尝试复制并粘贴它:
[99 ,1, "3/03/2011", ["ScrewDriver", "Hammer", "Stone"]] [2 ,2, "3/03/2011", ["hammer,nails"]] [31 ,2, "3/03/2011", ["plaster,studd"]] [100 ,2, "3/03/2011", ["hammer,studd"]]
I'm not sure if you see them, but look closely at those quotation marks:
[1,'1','3/03/2011', [“ScrewDriver”, “Hammer”, “Stone”]]
There's a difference between this:
”
and this:
"
The first one (
”
) is a curly quote, which screws up the interpreter. Use normal quotes ("
) and post back what your script returns then.Also, what does this
return
statement do:return (new)
If you're in a function, the function will quit upon the first iteration of the list, as it
return
s every single loop, but only the first one is caught and the function dies there.I'd move the
return
statement down a level so it isn't part of thefor
loop. So change this:for line in lines: listline=eval(line) if not(num_del==list_line[0]): new +=(line + "\n") return (new)
To this:
for line in lines: listline=eval(line) if not(num_del==list_line[0]): new +=(line + "\n") return (new)
This is your text file without the curly quotes. Try copy and pasting it:
[99 ,1, "3/03/2011", ["ScrewDriver", "Hammer", "Stone"]] [2 ,2, "3/03/2011", ["hammer,nails"]] [31 ,2, "3/03/2011", ["plaster,studd"]] [100 ,2, "3/03/2011", ["hammer,studd"]]
相关问答
更多在Python 3.3中写入txt文件的上一行(Writing to the previous line of a txt file in Python 3.3)
通过匹配行中的数字,使用python删除.txt中的一行(delete a line in .txt using python by matching the number in the line)
匹配txt文件中的每个单词(Matching every word in a txt file)
如何将.txt内容导入python 2.7中的一行代码(how to import .txt contents into a line of code in python 2.7)
如何删除txt文件中的第一行(how to delete first line in a txt file)
如何在Python中访问文件(.txt)中的下一行(How to access next line in a file(.txt) in Python)
使用.txt文件行的内容作为python3变量的输入(Use content of .txt file line as input for python3 variable)
使用python将字符附加到txt文件中的每一行(Appending characters to each line in a txt file with python)
替换python代码中的字符串并减少下一行中的数字(replace strings in python code and decrement number in the next line)
如何逐行读取python中的txt文件并将每一行设置为变量(How to read txt file in python line by line and set each line to a variable)
相关文章
更多jpa与hibernate注解混合使用
spring 3.0 和jpa 整合 用jboss
Spring +JPA 多持久化单元 怎么配置
【第八章】 对ORM的支持 之 8.4 集成JPA ——跟我学spring3
JPA环境配置
Spring MVC 3 深入总结
基于struts2.18+spring3.0+hibernate3.5+annotation的用户权限
Spring与Hibernate集成中的session问题
Spring Data: a new perspective of data operations
JPA ORM框架介绍
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!