-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: java.sql.SQLException: Fail to convert to internal represent
PostPosted: Tue Sep 18, 2007 11:41 am 
Newbie

Joined: Tue Jul 26, 2005 10:25 am
Posts: 12
I'm having issues with an embedded list within one of my persistent objects. When I attempt to get one of the Lists within the entity (in a JSP via a viewhelper class), an exception is thrown (the root exception is java.sql.SQLException: Fail to convert to internal representation). In a debug window, I'm seeing a LazyInitializationException, which is likely related.

I'm completely stumped, and hope somewhere out there, someone can help. All I can think of is that I have a mapping issue.

I have these classes:

Code:
package mine;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
* Please Fill in this Javadoc
*
* @author Jason
*/

@Entity
@Table(name = "T_EQUIPMENTACCOUNT")
public class EquipmentAccount implements Serializable, Comparable {

    private int id;
    private String name;

    private List<User> primaryCustodian;
    private List<User> alternateCustodians;

    private List<EquipmentItem> accountInventory;

    @Id
    @Column(name = "ACCOUNTID")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ACCOUNTID_SEQ")
    @SequenceGenerator(name = "ACCOUNTID_SEQ", sequenceName = "S_ADPEACCOUNT")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }


    @Column(name = "ACCOUNTNAME")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @OneToMany
    @JoinTable(name = "T_PRIMARYCUSTODIANS",
            joinColumns = {@JoinColumn(name = "ADPEACCOUNTID")},
            inverseJoinColumns = {@JoinColumn(name = "PCUSTODIANID")})
    public List<User> getPrimaryCustodian() {
        return primaryCustodian;
    }

    public void setPrimaryCustodian(List<User> primaryCustodian) {
        this.primaryCustodian = primaryCustodian;
    }

    @OneToMany
    @JoinTable(name = "T_ACCOUNT_ALTCUSTODIANS_LINK",
            joinColumns = {@JoinColumn(name = "ADPEACCOUNTID")},
            inverseJoinColumns = {@JoinColumn(name = "CUSTODIANID")})
    public List<User> getAlternateCustodians() {
        return alternateCustodians;
    }

    public void setAlternateCustodians(List<User> alternateCustodians) {
        this.alternateCustodians = alternateCustodians;
    }

    @OneToMany(targetEntity = EquipmentItem.class)
    @JoinTable(name="T_ACCT_ITEM_LINK",
        joinColumns = {@JoinColumn(name="ACCOUNTID")},
            inverseJoinColumns = {@JoinColumn(name="ITEMID")})
    public List<EquipmentItem> getAccountInventory() {
        return accountInventory;
    }

    public void setAccountInventory(List<EquipmentItem> accountInventory) {
        this.accountInventory = accountInventory;
    }


    public int compareTo(Object o) {
        String o1 = this.getName();
        String o2 = (((EquipmentAccount) o).getName());

        return o1.compareTo(o2);
    }
}


Here is the EquipmentItem class:

Code:
package mine;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Date;
import java.util.List;

@Entity
@Table(name = "T_EQUIPMENTITEM")
public class EquipmentItem implements Serializable {

    private int id;

    private String serial;
    private String manufacturer;
    private String model;
    private String description;
    private double orginalCost;
    private EquipmentAccount account;
    private ItemStatus status;
    private EquipmentType itemType;
    private ItemCondition itemCondition;

    @Id
    @Column(name = "ITEMID")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ITEMID_SEQ")
    @SequenceGenerator(name = "ITEMID_SEQ", sequenceName = "S_EQUIPMENTITEM")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Column(name = "SERIAL")
    public String getSerial() {
        return serial;
    }

    public void setSerial(String serial) {
        this.serial = serial;
    }

    @Column(name = "MANUFACTURER")
    public String getManufacturer() {
        return manufacturer;
    }

    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }

    @Column(name = "MODEL")
    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    @Column(name = "DESCRIPTION")
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Column(name = "ORIGINALCOST")
    public double getOrginalCost() {
        return orginalCost;
    }

    public void setOrginalCost(double orginalCost) {
        this.orginalCost = orginalCost;
    }


    @ManyToOne(targetEntity = AdpeAccount.class)
    @JoinColumn(name = "ADPEACCOUNTID", insertable = false, updatable = false)
    public AdpeAccount getAccount() {
        return account;
    }

    public void setAccount(AdpeAccount account) {
        this.account = account;
    }

    @ManyToOne
    @JoinColumn(name = "ITEMSTATUSID")
    public ItemStatus getStatus() {
        return status;
    }

    public void setStatus(ItemStatus status) {
        this.status = status;
    }


    @ManyToOne
    @JoinColumn(name = "TYPEID")
    public EquipmentType getItemType() {
        return itemType;
    }

    public void setItemType(EquipmentType itemType) {
        this.itemType = itemType;
    }

    @ManyToOne
    @JoinColumn(name = "ITEMCONDITIONID")
    public ItemCondition getItemCondition() {
        return itemCondition;
    }

    public void setItemCondition(ItemCondition itemCondition) {
        this.itemCondition = itemCondition;
    }

    @Transient
    public double getDepreciatedValue() {

        throw new UnsupportedOperationException();
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        final EquipmentItem that = (EquipmentItem) o;

        if (!manufacturer.equals(that.manufacturer)) return false;
        if (!serial.equals(that.serial)) return false;

        return true;
    }

    public int hashCode() {
        int result;
        result = serial.hashCode();
        result = 29 * result + manufacturer.hashCode();
        return result;
    }

}


Finally, here is (most of) the ViewHelper that attempts to get the equipment list (not the most efficient implementation yet...)

Code:
package mine;

// Misc Imports snipped for space

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.PageContext;
import java.util.Collections;
import java.util.List;


/**
* Viewhelper class for displaying AdpeAccount related information
*
* @author TSgt Jason Ferguson
*/

public class AdpeAccountViewHelper implements PageContextAwareBean {

    private AdpeAccountService adpeAccountService;

    public void setAdpeAccountService(AdpeAccountService adpeAccountService) {
        this.adpeAccountService = adpeAccountService;
    }

    private PageContext pageContext;

    public void setPageContext(PageContext pageContext) {
        this.pageContext = pageContext;
    }

    private AdpeAccount adpeAccount;

    public void setAdpeAccount(AdpeAccount adpeAccount) {
        this.adpeAccount = adpeAccount;
    }

    public List<AdpeAccount> getAll() {

        return adpeAccountService.getAll();
    }


    public List<EquipmentItem> getEquipmentList() {


        int id = (Integer) pageContext.getRequest().getAttribute("accountId");

        if (this.adpeAccount == null) {
            this.adpeAccount = adpeAccountService.getById(id);
        } else {
            if (this.adpeAccount.getId() == id) {
            } else {
                this.adpeAccount = adpeAccountService.getById(id);

            }
        }

        AdpeAccount adpeAccount = adpeAccountService.getById(id);

        List<EquipmentItem> itemList = adpeAccount.getAccountInventory();
        Collections.sort(itemList, new EquipmentItemSerialComparator());
        Collections.sort(itemList, new EquipmentItemManufacturerComparator());

        return itemList;
    }

}





Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.2.5 (Annotations 3.3.0.GA)

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

500 Internal Server Error

Exception: [.LookupUtil] Error looking up property "equipmentList" in object type "mine.equipmenttracker.web.helpers.EquipmentAccountViewHelper". Cause: null
at org.displaytag.util.LookupUtil.getBeanProperty(LookupUtil.java:137)
at org.displaytag.util.LookupUtil.getBeanValue(LookupUtil.java:90)
at org.displaytag.tags.TemplateTag.evaluateExpression(TemplateTag.java:84)
at org.displaytag.tags.TableTag.initParameters(TableTag.java:847)
at org.displaytag.tags.TableTag.doStartTag(TableTag.java:722)
at _web_2d_inf._jsp._viewAccountProfile._jspService(_viewAccountProfile.java:386)
[SRC:/WEB-INF/jsp/viewAccountProfile.jsp:67]
at com.orionserver[Oracle Containers for J2EE 10g (10.1.3.2.0) ].http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
at oracle.jsp.runtimev2.JspPageTable.compileAndServe(JspPageTable.java:724)
at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:414)
at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:597)
at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:521)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.2.0) ].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:712)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.2.0) ].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:369)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.2.0) ].server.http.ServletRequestDispatcher.unprivileged_forward(ServletRequestDispatcher.java:286)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.2.0) ].server.http.ServletRequestDispatcher.access$100(ServletRequestDispatcher.java:50)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.2.0) ].server.http.ServletRequestDispatcher$2.oc4jRun(ServletRequestDispatcher.java:192)
at oracle.oc4j.security.OC4JSecurity.doPrivileged(OC4JSecurity.java:283)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.2.0) ].server.http.ServletRequestDispatcher.forward(ServletRequestDispatcher.java:197)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:398)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.2.0) ].server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)
at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:118)
at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.2.0) ].server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15)
at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271)
at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.2.0) ].server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:17)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:265)
at mine.equipmenttracker.util.SpringFilter2.doFilter(SpringFilter2.java:107)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107)
at org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:166)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:149)
at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.2.0) ].server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:17)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.2.0) ].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:620)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.2.0) ].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:369)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.2.0) ].server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:865)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.2.0) ].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:447)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.2.0) ].server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:215)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.2.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:117)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.2.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:110)
at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.2.0) ].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:1773)
at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1132)
at org.apache.commons.beanutils.PropertyUtils.getSimpleProperty(PropertyUtils.java:408)
at org.displaytag.util.LookupUtil.getProperty(LookupUtil.java:271)
at org.displaytag.util.LookupUtil.getBeanProperty(LookupUtil.java:129)
... 59 more
Caused by: org.hibernate.exception.GenericJDBCException: could not initialize a collection: [mine.equipmenttracker.model.EquipmentAccount.accountInventory#1000]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2001)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.PersistentBag.toArray(PersistentBag.java:257)
at java.util.Collections.sort(Unknown Source)
at mine.equipmenttracker.web.helpers.EquipmentAccountViewHelper.getEquipmentList(EquipmentAccountViewHelper.java:199)
... 68 more
Caused by: java.sql.SQLException: Fail to convert to internal representation
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:138)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:175)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:240)
at oracle.jdbc.driver.CharCommonAccessor.getInt(CharCommonAccessor.java:146)
at oracle.jdbc.driver.OracleResultSetImpl.getInt(OracleResultSetImpl.java:508)
at oracle.jdbc.driver.OracleResultSet.getInt(OracleResultSet.java:1618)
at org.hibernate.type.IntegerType.get(IntegerType.java:28)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2096)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1380)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1308)
at org.hibernate.loader.Loader.getRow(Loader.java:1206)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
at org.hibernate.loader.Loader.doQuery(Loader.java:701)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1994)
... 77 more

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.