我目前正在研究Felix的OSGi项目(v4.0.3).我需要使用JPA,所以我安装了Apache Aries JPA包.我还安装了OpenJPA,我需要它使用MySQL Connector Bundle连接到MySQL数据库.不幸的是它不起作用,OpenJPA说它无法找到MySQL JDBC类,我无法弄清楚什么是坏的,也许我做错了.我将在下面解释我安装的内容以及persistence.xml文件和我得到的实际异常.
这是我安装的Apache Aries软件包列表:
然后我安装了那些Apache Aries JPA包的依赖项.我从Springsource下载了它们:
我还安装了OpenJPA及其所有依赖项.我在apache-openjpa-2.2.0下载文件夹的lib文件夹中找到了bundle 2到5(commons-*).我在这里下载了Serp ,因为在lib文件夹中找到的jar不是OSGi包.最后我找到了Springsource中的最后两个包(#7和#8):
一旦我最终安装了OpenJPA,我仍然需要MySQL JDBC Driver包,我也从Springsource存储库获得了它的commons-logging依赖:
现在,此时安装的软件包列表变得非常庞大.我说我安装了OpenJPA,但这只是因为我无法弄清楚如何使用任何其他提供商与Aries.我最初想使用EclipseLink,但显然Apache Aries没有检测到它作为提供者,根据这个博客,你必须制作另一个包含你自己的激活器的包,让Aries注意到EclipseLink.我尝试了但它没有用,所以我又回到了使用OpenJPA.
所以现在我有两个问题:
或者:
这是我使用的persistence.xml文件:
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="userManager.model" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>org.project.dao.entity.UserEntity</class>
<properties>
<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver" />
<property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/usermanager?autoReconnect=true" />
<property name="openjpa.ConnectionUserName" value="root" />
<property …Run Code Online (Sandbox Code Playgroud) 我编写了一个带有Field LoginId和Password的权限类.
Iam使用AES_ENCRYPT加密passwrd并在db中加载它.
我想只检索解密的密码.所以,我在OPen JPA 2.0中使用NAEDQueryis使用AES_DECRYPT.
我写的查询是:
Query q = em.createNativeQuery("select AES_DECRYPT(l.password,?2) from loginDetails l where l.loginID = ?1");
q.setParameter(1, loginId);
q.setParameter(2, getKey());
String s = q.getSingleResult();
Run Code Online (Sandbox Code Playgroud)
但我得到以下例外:
java.lang.ClassCastException: [B cannot be cast to java.lang.String
at com.rcs.chef.validation.UserValidation.decryptedPasswordForID(UserValidation.java:99)
at com.rcs.chef.validation.UserValidation.validateUser(UserValidation.java:81)
at com.rcs.chef.validation.UserValidation.activate(UserValidation.java:72)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:226)
at org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:824)
at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:636)
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:724)
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:64)
at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:219)
at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:147)
at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:640)
at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:331)
at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:227)
Run Code Online (Sandbox Code Playgroud)
我甚至试过这个:
Query q = em.createNativeQuery("select AES_DECRYPT(l.password,?2) from loginDetails l where …Run Code Online (Sandbox Code Playgroud) 有没有办法按照它们在Java类中声明的顺序获取列,或者以其他方式指定顺序?
我正在使用映射工具ant任务在sql文件中为我的类生成DDL.
我有一个Oracle函数,它接受一个POINTS%ROWTYPE表.我想使用CriteriaBuilder类从JPA调用此函数,该类具有数据库函数的功能.当我尝试构建查询时,它会死于抱怨ArrayLists不是函数的有效查询参数.
如何将ArrayList中的ArrayList传入Oracle函数?
Oracle函数签名:
CREATE OR REPLACE FUNCTION LOCATION_CONTAINS
(
LATITUDE_IN IN DOUBLE PRECISION,
LONGITUDE_IN IN DOUBLE PRECISION,
points IN types_pkg.point_array,
numPoints IN INTEGER
)
Run Code Online (Sandbox Code Playgroud)
Oracle类型:
create or replace package types_pkg
as
type point_array is table of FILTERPOINT%ROWTYPE;
end types_pkg;
Run Code Online (Sandbox Code Playgroud)
JPA Criteria Builder调用
List<FilterPoint> points = getPoints(location_name);
int numPoints = points.size();
Expression ex =
cb.function( "LOCATION_CONTAINS",
Integer.class,
entity.get( "latitude" ),
entity.get( "longitude" ),
cb.literal( points ),
cb.literal( numPoints ) );
Run Code Online (Sandbox Code Playgroud)
例外:
org.apache.openjpa.persistence.ArgumentException:
The specified parameter of type "class middle.ware.FilterPoint" is not …Run Code Online (Sandbox Code Playgroud) 给定一个example_table带有以下列的简单table():id, first_name, last_name是否可以通过执行JPA本机sql查询来em.createNativeQuery("select * from example_table")检索列名和数据?getResultList()在查询上运行仅返回数据.我怎样才能检索列名?
我的部门决定转向我们的一些大型Oracle数据库进行哈希分区/分片.我们将跨越不同的模式分割我们的实体.我的任务是做一个尖峰来评估不同JPA实现的适用性.
我告诉要关注的两个是EclipseLink和Apache OpenJPA/Slice.我们过去只使用过Hibernate,但是Hibernate Shards处于测试阶段,并且似乎不再积极开发(最新版本是在2007年),所以我们没有考虑它.
我将进行自己的评估和试验实施,但我不相信在我获得这些实现的时候,我会对这些实现的整体质量有一个良好的感觉.如果您在生产环境中使用OpenJPA和/或EclipseLink,特别是如果您的数据库已经共享,我希望了解您的体验(正面和负面),您对其整体质量的看法,以及您是否也这样做如果有机会再次选择.
当我尝试调用100%正常工作的代码时,我从eclipse中得到错误.例如,它在我的netbeans中工作,但不是这个eclipse项目.错误是荒谬的,我几乎可以肯定它是由我正在使用的OPEN JPA的一些Maven依赖引起的.有什么指针吗?
Map<String,String> properties = new HashMap<String,String>();
properties.put(PersistenceUnitProperties.JDBC_PASSWORD, "");
properties.put(PersistenceUnitProperties.JDBC_USER, "root");
properties.put(PersistenceUnitProperties.JDBC_URL, "jdbc:mysql://localhost:3306/mydb");
properties.put(PersistenceUnitProperties.JDBC_DRIVER, "com.mysql.jdbc.Driver");
emf = Persistence.createEntityManagerFactory("Persistentunitname", properties);
Run Code Online (Sandbox Code Playgroud)
错误发生在最后一行,错误是:
ClassFormat错误"在类文件javax/persistence/Persistence中不是本机或抽象的方法中的Absent Code属性"
这让我发疯,我很惊讶官方文档绝对是用途.
这是我有的:
由于openjpa被添加到已使用的库列表中,我已经有了OpenJPA的类路径,如下所示
<path id="library.openjpa.classpath">
<fileset dir="${basedir}/lib/openjpa">
<patternset refid="library.patterns"/>
</fileset>
</path>
Run Code Online (Sandbox Code Playgroud)
根据官方文档,我添加了以下目标
<target name="enhance">
<copy includeemptydirs="false" todir="${basedir}/lib/openjpa">
<fileset dir="src" excludes="**/*.launch, **/*.java"/>
</copy>
<taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask">
<classpath refid="library.openjpa.classpath"/>
</taskdef>
<openjpac>
<classpath refid="library.openjpa.classpath"/>
</openjpac>
</target>
Run Code Online (Sandbox Code Playgroud)
它给了我例外
C:\ work\prj\build.xml:283:org.apache.openjpa.util.MetaDataException:无法配置MetaDataFactory(conf.newMetaDataFactoryInstance()返回null).这可能意味着找不到配置属性.确保您具有META-INF/persistence.xml文件,它在类路径中可用,或者您用于配置的属性文件可用.如果您使用的是Ant,请参阅任务嵌套元素的或属性.如果您的OpenJPA分发包损坏,或者您的安全策略过于严格,也会发生这种情况.
我使用Process Monitor进行了测试,可以看到它打开并读取 persistence.xml.
有人提出我遇到问题的bug,他得到的答案是找不到persistence.xml问题的根源.
问题是:
persistence.xml并仅为我希望增强的.class文件指定模式来使其工作吗?persistence.xml在目录以外的目录中查找openjpa-2.1.1.jar?我正在使用open-jpa,因为我们知道它随增强器一起提供,可以在增强期间创建非私有的无参数构造函数.它有效,但是日食有问题.它非常合理,它不知道在ant构建期间会发生什么,所以是否有可能关闭这个The Java class for mapped type ... must define a non-private zero-argument constructor与@Entity注释绑定的特定错误?
如何正确公开延迟加载的多个字段,以便用户在Spring Data REST中可以GET/ PATCH/ POST/ DELETE多个实体关系?
例如,给定一个由多对多关系绑定的Student实体和Teacher实体,使用以下POJO:
@Entity
public class Teacher { // owner of bidirectional relationship
@Id
private int id;
private String name;
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "teacher_student",
joinColumns = @JoinColumn(name = "teacher_id"),
inverseJoinColumns = @JoinColumn(name = "student_id"))
private Set<Student> students;
// Constructor, getters/setters...
}
@Entity
public class Student {
@Id
private int id;
private String name;
@ManyToMany(mappedBy = "students", fetch = FetchType.LAZY)
private Set<Teacher> …Run Code Online (Sandbox Code Playgroud)