簡體   English   中英

EclipseLink中具有動態實體的序列

[英]Sequences with Dynamic Entities in EclipseLink

我正在嘗試使用動態實體獲取序列以在EclipseLink中工作,我需要一些幫助。

我正在定義我的動態實體,如下所示:

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("default");
    EntityManager em = emf.createEntityManager();

    Session session = JpaHelper.getEntityManager(em).getServerSession();
    DynamicClassLoader dcl = DynamicClassLoader.lookup(session);

    Class<?> testClass = dcl.createDynamicClass("org.persistence.Test");

    JPADynamicTypeBuilder test = new JPADynamicTypeBuilder(testClass, null, "TEST");

    test.addDirectMapping("id", long.class, "T_ID");
    test.setPrimaryKeyFields("T_ID");
    test.addDirectMapping("col1", long.class, "T_COL1");
    test.addDirectMapping("col2", int.class, "T_COL2");
    test.addDirectMapping("col3", String.class, "T_COL3");
    test.addDirectMapping("col4", String.class, "T_COL4");
    test.addDirectMapping("col5", double.class, "T_COL5");
    test.addDirectMapping("col6", double.class, "T_COL6");

    DynamicHelper helper = new JPADynamicHelper(em);
    helper.addTypes(true, true, test.getType());

我注意到,所有內容都是根據指​​定的內容創建的。 我試圖尋找一些有關如何使用數據庫序列的文檔,並且注意到JPADynamicTypeBuilder.configureSequencing(Sequence,String,String)方法。 但我找不到有關如何執行此操作的任何示例。 我玩弄了這種方法,總是以默認的排序策略結束,即名為SEQUENCE的表。

我嘗試使用@GeneratedValue和@SequenceGenerator對預編譯的實體進行測試,並且一切正常,因此我對動態實體做錯了。

有誰知道我可能做錯了什么?

似乎無關緊要,但是無論如何我要告訴我的數據庫是Oracle。

提前致謝,

我沒有您的Sequence對象的詳細信息,因此我的示例只是通用的,但類似以下內容的方法應該起作用:

test.configureSequencing(
      new NativeSequence("ORACLE_SEQ_OBJ", 1, 1),
      "ORACLE_SEQ_OBJ",
      "T_ID");

您可以在JPADynamicTypeBuilder上使用configureSequencing方法來設置序列。

這是一個很好的例子: http : //dev.eclipse.org/svnroot/rt/org.eclipse.persistence/branches/2.1/trunk/examples/jpa.employee/eclipselink.example.jpa.employee.dynamic/src/example /EmployeeDynamicMappings.java

我仍在嘗試使其與表排序一起使用,但給我一個錯誤:

Exception [EclipseLink-41] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A non-read-only mapping must be defined for the sequence number field.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM