2014-03-12 34 views
2

我在JBoss上運行Java應用程序使用的EclipseLink堅持到Postgres數據庫無法插入到路徑字段。我已經添加了「路徑」數據類型的字段的表之一,但我不斷收到異常當我嘗試插入數據。PostgreSQL的:使用的EclipseLink

這裏的表定義:

CREATE TABLE schema.table_name 
(
    item_id uuid NOT NULL, 
    item_path path NOT NULL 
) 

的Java的實體是代表item_path字段列表對象,我使用一個轉換器映射來自List對象的PGpath對象:

import org.eclipse.persistence.mappings.DatabaseMapping; 
import org.eclipse.persistence.mappings.converters.Converter; 
import org.eclipse.persistence.sessions.Session; 
import org.postgresql.geometric.PGpath; 
import java.awt.Point; 
import java.util.ArrayList; 
import java.util.List; 
import static java.sql.Types.OTHER; 

public class PgPathConverter implements Converter 
{ 
    @Override 
    public boolean isMutable() 
    { 
     return false; 
    } 

    @Override 
    public List<Point> convertDataValueToObjectValue (Object value, Session session) 
    { 
     // Code that converts PGpath to List<Point> 
    } 

    @Override 
    public PGpath convertObjectValueToDataValue (Object value, Session session) 
    { 
     // Code that converts List<Point> to PGpath 
    } 

    @Override 
    public void initialize (DatabaseMapping mapping, Session session) 
    { 
     mapping.getField().setSqlType (OTHER); 
    } 
} 

實體類的定義如下:

@Entity 
@Table (
    name   = "table_name", 
    schema   = "schema" 
) 
@Converter (
    name   = "path", 
    converterClass = PgPathConverter.class 
) 
public class TableName 
{ 
    public TableName() {} 
    private static final long serialVersionUID = 1L; 

    @Column (name = "item_path") 
    @Convert ("path") 
    private List<Point> m_ItemPath; 

    @Id 
    @Column (
     name  = "item_id", 
     unique = true, 
     nullable = false 
    ) 
    private UUID  m_ItemId; 

    public UUID getItemId() 
    { 
     return m_ItemId; 
    } 

    public List<Point> getItemPath() 
    { 
     return m_InkPath; 
    } 

    public void setItemId (UUID itemId) 
    { 
     m_ItemId = itemId; 
    } 

    public void setInkPath (List<Point> itemPath) 
    { 
     m_ItemPath = itemPath; 
    } 
} 

最後,這裏的EXC主器件接收我得到當我打電話EntityManager.persist (entity)

18:10:33,789 ERROR [org.jboss.as.ejb3] (http-/0.0.0.0:8080-1) javax.ejb.EJBTransactionRolledbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException 
Internal Exception: org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of org.postgresql.geometric.PGpath. Use setObject() with an explicit Types value to specify the type to use. 
Error Code: 0 
Call: INSERT INTO schema.table_name (item_id, item_path) VALUES (?, ?) 
bind => [2 parameters bound] 
18:10:33,789 ERROR [org.jboss.as.ejb3.invocation] (http-/0.0.0.0:8080-1) JBAS014134: EJB Invocation failed on component TableNameRepository for method public void com.mycompany.myproject.data.Repository.flush() throws javax.persistence.TransactionRequiredException,javax.persistence.PersistenceException: javax.ejb.EJBTransactionRolledbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException 
Internal Exception: org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of org.postgresql.geometric.PGpath. Use setObject() with an explicit Types value to specify the type to use. 
Error Code: 0 
Call: INSERT INTO schema.table_name (item_id, item_path VALUES (?, ?) 
bind => [2 parameters bound] 
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleInCallerTx(CMTTxInterceptor.java:138) [jboss-as-ejb3-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8] 
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:228) [jboss-as-ejb3-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8] 
at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:317) [jboss-as-ejb3-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8] 
at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:214) [jboss-as-ejb3-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8] 
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-2.jar:1.1.1.Final-redhat-2] 
at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8] 
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-2.jar:1.1.1.Final-redhat-2] 
at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64) [jboss-as-ejb3-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8] 
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-2.jar:1.1.1.Final-redhat-2] 
at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [jboss-as-ejb3-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8] 
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-2.jar:1.1.1.Final-redhat-2] 
at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [jboss-as-ee-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8] 
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-2.jar:1.1.1.Final-redhat-2] 
at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:55) [jboss-as-ejb3-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8] 
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-2.jar:1.1.1.Final-redhat-2] 
at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8] 
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-2.jar:1.1.1.Final-redhat-2] 
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final-redhat-2.jar:1.1.1.Final-redhat-2] 
at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165) [jboss-as-ee-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8] 
at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:182) [jboss-as-ee-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8] 
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-2.jar:1.1.1.Final-redhat-2] 
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final-redhat-2.jar:1.1.1.Final-redhat-2] 
at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:72) [jboss-as-ee-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8] 

我手動輸入一些數據表,看看我是否能成功地從使用的EclipseLink表中提取數據。現在,在我的轉換方法convertDataValueToObjectValue拋出以下異常:

java.lang.ClassCastException: org.postgresql.geometric.PGpath cannot be cast to org.postgresql.geometric.PGpath 
+0

我加入時,我嘗試從表中提取數據與EclipseLink的正被拋出的異常編輯我的問題。 –

回答

0

原來,這是與我是如何配置我的JBoss應用程序有問題。我有JDBC驅動程序的jar的多個副本,一個在部署EAR文件和一個在JBoss容器。因爲每個廣口瓶由一個單獨的類裝入器裝入這是造成混亂。 Java通過其全名和ClassLoader來識別類。

,因爲我已添加了驅動程序jar作爲一個模塊到JBoss服務器,我需要從部署的EAR刪除驅動程序jar,並設置一個依賴於在JBoss服務器模塊。

此鏈接有一些更多的細節:https://community.jboss.org/message/862434

相關問題