氟塑料离心泵www.buybeng.com

jquery教程http://www.software8.co/wzjs/jquery/

JPA 无法加载独立JAR包中实体映射文件 unkonwn entity

在实际的项目中,原先大的项目,需要按业务功能拆分成小功能,并且以服务的方式独立布署。

在此前提下,同时也为了应用各工程 ,使用同一代码,为了方便。单独以jar包方式,作为其他工程 引入,使用。

我们在独立的JAR包,设置了独立的数据源文件,映射实体。

但在项目整合的时候遇到不能加载配置文件跟实体映射。

我们在实体文件中全部使用JPA实体映射。@Entity

在具体使用中,抛出异常unkonwn entity xxxx

下文参考地址:http://www.software8.co/wzjs/java/2930.html
原因有二:

1 .web.xml 需要指定 classpath*:applicationContext-*.xml 特别是classpath* 这样才会扫描jar 包中的配置文件。否则只加载项目下的。

2.persistence.xml 文件中,需要指定JAR包的文件所在

在节点provider 同级下设置 jar-file 指定绝对目录或者文件。

具体请参考 http://docs.jboss.org/hibernate/entitymanager/3.5/reference/en/html/configuration.html#d0e215

posted on 2013-02-05 13:15 你爸是李刚 阅读(1995) 评论(3)  编辑  收藏

评论

# re: JPA 无法加载独立JAR包中实体映射文件 unkonwn entity 2013-02-05 14:52 11

public void sendToPDM() throws Exception {

wt.fc.ReferenceFactory rf = new wt.fc.ReferenceFactory();
try {
String oid = "VR:wt.part.WTPart:8532216";
WTKeyedHashMap wtkeyedhashmap = new WTKeyedHashMap(1, 2);
WTPart part = (WTPart) rf.getReference(oid).getObject();
if (wt.inf.sharing.DataSharingHelper.isShared(part)) {

System.out.println("is share ");

wtkeyedhashmap.put(rf.getReference(oid).getKey(), null);
} else {
System.out.println("is not share ");
List<String> list = new ArrayList<String>();
list.add(oid);
PDMLinkProduct product = (PDMLinkProduct) rf.getReference(
"OR:wt.pdmlink.PDMLinkProduct:41994").getObject();
Folder folder = (Folder) rf.getReference(
"OR:wt.folder.SubFolder:8532417").getObject();
processNewObjects(list, wtkeyedhashmap, folder, product);
}

InitialCheckinDataApplicator initialcheckindataapplicator = new InitialCheckinDataApplicator(
false);
Map map = SandboxHelper.service.checkin(wtkeyedhashmap,
" auto checkin", initialcheckindataapplicator, true, true);
processKeepCheckedOutObjects(map, false);
System.out.println("....end");
} catch (Exception e) {
e.printStackTrace();
}

}

protected String getName(Object obj) throws WTException {
String s = null;
try {
Method method = obj.getClass().getMethod("getName", null);
s = (String) method.invoke(obj, null);
} catch (Exception exception) {
throw new WTException(exception);
}
return s;
}

protected String getNumber(Object obj) throws WTException {
String s = null;
try {
Method method = obj.getClass().getMethod("getNumber", null);
s = (String) method.invoke(obj, null);
} catch (Exception exception) {
throw new WTException(exception);
}
return s;
}  回复  更多评论   

# re: JPA 无法加载独立JAR包中实体映射文件 unkonwn entity 2013-02-05 14:53 11

protected void processNewObjects(List list, WTKeyedMap wtkeyedmap,
Folder targetfolder, WTContainer targetContainer)
throws WTException {

Iterator iterator = list.iterator();
wt.fc.ReferenceFactory rf = new wt.fc.ReferenceFactory();

do {
if (!iterator.hasNext())
break;
String oid = (String) iterator.next();
String s = "";
String s1 = "";
String s2 = "";
InitialCheckinData initialcheckindata = new InitialCheckinData();
WTReference wtreference = getInteroperable(oid);
Persistable persistable = (Persistable) rf.getReference(oid)
.getObject();

s = getName(persistable);
s1 = getNumber(wtreference.getObject());
initialcheckindata.setFolder(targetfolder);
initialcheckindata.setTargetContainerRef(WTContainerRef
.newWTContainerRef(targetContainer));
initialcheckindata.setRenumberIfRequired(false);
initialcheckindata.setNumber(s1);
initialcheckindata.setName(s);
initialcheckindata.setCadName(s2);
initialcheckindata.setView(ViewReference
.newViewReference(ViewHelper.service.getView("Design")));
wtkeyedmap.put(wtreference, initialcheckindata);
} while (true);
}

protected WTReference getInteroperable(String oid) throws WTException {

wt.fc.ReferenceFactory rf = new wt.fc.ReferenceFactory();
wt.fc.WTReference obj = rf.getReference(oid);
if (!wt.sandbox.Interoperable.class
.isAssignableFrom(((WTReference) (obj)).getReferencedClass())) {
throw new WTException("error");
}
if (!(obj instanceof VersionReference)) {
obj = VersionReference
.newVersionReference((Interoperable) (Interoperable) ((WTReference) (obj))
.getObject());
}
return ((WTReference) (obj));
}
  回复  更多评论   

# re: JPA 无法加载独立JAR包中实体映射文件 unkonwn entity 2013-02-05 14:54 11

protected WTReference getInteroperable(String oid) throws WTException {

wt.fc.ReferenceFactory rf = new wt.fc.ReferenceFactory();
wt.fc.WTReference obj = rf.getReference(oid);
if (!wt.sandbox.Interoperable.class
.isAssignableFrom(((WTReference) (obj)).getReferencedClass())) {
throw new WTException("error");
}
if (!(obj instanceof VersionReference)) {
obj = VersionReference
.newVersionReference((Interoperable) (Interoperable) ((WTReference) (obj))
.getObject());
}
return ((WTReference) (obj));
}

public static Map processKeepCheckedOutObjects(Map map, boolean ischeckout)
throws WTException, WTPropertyVetoException {

Folder folder = null;
WTHashSet wthashset = new WTHashSet(map.size());
Iterator iterator = map.entrySet().iterator();
do {
if (!iterator.hasNext())
break;
java.util.Map.Entry entry = (java.util.Map.Entry) iterator.next();
WTReference wtreference = (WTReference) entry.getKey();
Persistable persistable = wtreference.getObject();
if (ischeckout) {
if (folder == null && (persistable instanceof FolderEntry))
folder = FolderHelper.getFolder((FolderEntry) persistable);
wthashset.add((WTReference) entry.getValue());
}
} while (true);

return performCheckoutToPrj(wthashset, folder);
}

public static Map performCheckoutToPrj(WTSet wtset, Folder folder)
throws WTException, WTPropertyVetoException {
Transaction transaction = null;
WTContainerRef wtcontainerref;
boolean flag = true;
Map map = null;
if (wtset == null || wtset.size() <= 0)
return map;
try {
WTContainer wtcontainer = folder.getContainer();
wtcontainerref = WTContainerRef.newWTContainerRef(wtcontainer);
transaction = new Transaction();
transaction.start();
flag = SessionServerHelper.manager.setAccessEnforced(false);
map = SandboxHelper.service.checkout(wtset, wtcontainerref, folder,
"", true);
SessionServerHelper.manager.setAccessEnforced(flag);

transaction.commit();
transaction = null;
if (transaction != null)
transaction.rollback();
} catch (Exception e) {
if (transaction != null)
transaction.rollback();
}
return map;
}  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
<2013年2月>
272829303112
3456789
10111213141516
17181920212223
242526272812
3456789

导航

统计

常用链接

留言簿

随笔档案

文章档案

技术网站

行业网站

搜索

最新评论

阅读排行榜

评论排行榜

站长网 氟塑料离心泵 注塑机 液晶广告机