MATLAB仅在前几秒钟内找到eclipselink的persistence.xml [英] MATLAB finds persistence.xml for eclipselink only within the first few seconds

查看:71
本文介绍了MATLAB仅在前几秒钟内找到eclipselink的persistence.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在Java中使用eclipselink中描述的问题的继续代码从MATLAB运行,并且与用于MATLAB的Java JPA类,但是此处描述的公认解决方案尚未完全解决问题.

This is a continuation of the issue described in Using eclipselink in Java code run from MATLAB and is similar to the issue described in Java JPA Class for MATLAB, but the accepted solutions described there have not completely solved the issue.

我正在尝试使用eclipselink连接到matlab中的oracle数据库.从前面帖子中的答案中,我将代码放在静态类路径上(在classpath.txt中).当我这样做时,就可以使用它,但前提是必须在载入Matlab后的最初几秒钟内(通过调用Persistence.createEntityManager(...))创建EntityManager.如果我在启动Matlab之后等待5秒钟以上,则完全相同的代码将给出未提供持久性"异常.我已经确认,它确实可以工作,但实际上它使用的是与之不同的类加载器.我唯一能想到的是,类路径是在与Matlab控制台不同的线程上初始化的,并且如果我快速运行它,则Matlab的OSGI类加载器尚未初始化,因此它使用默认的Java类加载器.

I am trying to use eclipselink to connect to an oracle database in matlab. From the answers in the previous posts, I put the code on the static classpath (in the classpath.txt). When I do this I am able to use it, but only if I create the EntityManager (via a call to Persistence.createEntityManager(...)) within the first few seconds after matlab loads. If I wait more than 5 second after starting up Matlab, the exact same code gives the "No Persistence provided" exception. I have confirmed that the times that it does work, it is actually using a different class loader than the times that it does not. The only thing that I can think of is that the classpath is initializing on a separate thread than the Matlab console and that if I run it quickly, then Matlab's OSGI classloader is not initialized yet so it uses the default java class loader.

这显然不是可接受的解决方案,并且似乎还没有真正解决Matlab类加载器找不到persistence.xml的原因.有人还有其他想法吗?可能是因为我如何初始化eclipselink?在我之前从事此代码工作的人,或者我除了找到将persistence.xml放入类路径中的META-INF文件夹外,都无法找到一种识别它的方法.

This is obviously not an acceptable solution and doesn't seem to have really solved the reason of why Matlab classloader can not find the persistence.xml. Does anyone have any further ideas? Could it possibly be in how I am initializing eclipselink? Neither the guy that worked on this code before me nor I have been able to figure out a way to get it to recognize the persistence.xml in any way other than putting it in the META-INF folder on the classpath.

推荐答案

我找到了一个可行的解决方案,尽管我对此并不满意.首次初始化PersistenceProviderResolverHolder时,它将构造一个称为DefaultPersistenceProviderResolver的私有内部类,该类在被询问时将在您的META-INF目录中找到persistence.xml.稍后,当您调用Persistence.createEntityManagerFactory()时,它将要求PersistenceProviderResolverHolder作为解析器,然后要求解析器找到persistence.xml.

I found a solution that works though I am not terribly happy with it. When the PersistenceProviderResolverHolder is first initialized it constructs a private inner class called DefaultPersistenceProviderResolver that when asked will find the persistence.xml in your META-INF directory. Later, when you call Persistence.createEntityManagerFactory() it will ask the PersistenceProviderResolverHolder for the resolver and then ask the resolver to find the persistence.xml.

在Matlab中运行它的问题是,在初始化期间的某个时候,为PersistenceProviderResolverHolder提供了一个Activator类,该类替代了默认的解析器.据我所知,这个Activator类试图使用OSGI查找任何持久性配置.理想情况下,我应该能够进行配置,使其也可以找到persistence.xml,但是到目前为止,我在此方面还没有成功.

The issue when you run this in Matlab is that at some time during initialization the PersistenceProviderResolverHolder is given an Activator class that replaces the default resolver. As far as I can tell, this Activator class tries to use OSGI to find any persistance configurations. Optimally I should be able to configure things such that it would also find the persistence.xml, but so far I have been unsuccessful at this.

我想出的解决方案是制作DefaultPersistenceProviderResolver类的自己的副本,并将其实例设置为PersistenceProviderResolverHolder中的解析器.这将替换已放入其中的Activator类,并将其返回以查找META-INF文件夹中的persistence.xml.我真的不喜欢这样做,但这是我在一周的工作中就能够上班的唯一解决方案.

The solution that I came up with is to make my own copy of the DefaultPersistenceProviderResolver class and set an instance of that as the resolver in the PersistenceProviderResolverHolder. This will replace the Activator class that had been put into it and return it to looking for the persistence.xml in the META-INF folder. I really don't like doing this, but it is the only solution that I have been able to get to work in a week of working on this.

这篇关于MATLAB仅在前几秒钟内找到eclipselink的persistence.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆