Question

Edit1: When Hibernate connected to MS-SQL, all columns and tables are scanning. Logs

But when Hibernate connected to DB2, it is trying to make out (render) again all tables and columns which include ''i'' letter. Logs

After I scanned the tables and columns I realised that all letters was big.In fact , every letter was big on DB2. Hibernate uses small letters for inquiry and because of DB2's big letter sensitivity it does not realise column names. For that reason, it gives an alarm which is in below,

WARN SqlExceptionHelper: SQL Error: -99999, SQLState: 42703 
15:15:22,025 ERROR SqlExceptionHelper: An undefined column name was detected.

How can I solve this problem?


I have to retrieve data from a table in db2 using jpa. When I try to execute a query using the entity manager I get errors don't know where is the problem exactly. My code running on MS-SQL and HSQL-DB... But I connect DB2 the message error : *

  • Query qry = em.createQuery("from Holding h where h.RDeleted=:arg1");-

    13:26:38,135 DEBUG SQL: select holding0_.HoldingId as HoldingId1_, holding0_.RDeleted as RDeleted1_, holding0_.InsertDate as InsertDate1_, holding0_.SavesUserId as SavesUse4_1_, holding0_.UpdateDate as UpdateDate1_, holding0_.Updater as Updater1_, holding0_.Description as Descript7_1_, holding0_.HoldingName as HoldingN8_1_ from Holding holding0_ where holding0_.RDeleted=? Hibernate: select holding0_.HoldingId as HoldingId1_, holding0_.RDeleted as RDeleted1_, holding0_.InsertDate as InsertDate1_, holding0_.SavesUserId as SavesUse4_1_, holding0_.UpdateDate as UpdateDate1_, holding0_.Updater as Updater1_, holding0_.Description as Descript7_1_, holding0_.HoldingName as HoldingN8_1_ from Holding holding0_ where holding0_.RDeleted=? 13:26:38,428 WARN SqlExceptionHelper: SQL Error: -99999, SQLState: 42703 13:26:38,428 ERROR SqlExceptionHelper: An undefined column name was detected.

But it query works:

Select h.holdingId, h.holdingName, h.description from Holding h

My Datasource:

<bean class="org.apache.commons.dbcp.BasicDataSource" id="dataSourceDB2_JT400" destroy-method="close">
        <property value="com.ibm.as400.access.AS400JDBCDriver" name="driverClassName"/> 
        <property value="jdbc:as400://192.168.1.1/GULERP" name="url"/> 
        <property value="user" name="username"/> 
        <property value="PW" name="password"/> 
        <property value="5" name="initialSize"/>
    </bean>

My entityManager:

<bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="erp" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true" />
                <property name="generateDdl" value="false" />
                <property name="databasePlatform" value="org.hibernate.dialect.DB2400Dialect" />
            </bean>
        </property>
        <property name="dataSource" ref="dataSourceDB2_JT400"/>
    </bean>

and My domain:

@Entity
@AccessType("field")
@Table(name = "Holding", uniqueConstraints = {@UniqueConstraint(columnNames={"HoldingName"})})
public class Holding extends BaseClass implements Serializable {

    transient static final long serialVersionUID = 5473887143181971744L;

    @Id
    @Column(name = "HoldingId", nullable = false, length=36)
    @GeneratedValue(generator="system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    private String holdingId;

    @Basic(optional = false)
    @Column(name = "HoldingName", nullable = false, length = 100)
    private String holdingName;

    @Column(name = "Description", length = 210)
    private String description;

    @OneToMany(mappedBy = "holdingId", fetch = FetchType.LAZY)
    private List<Company> companyList;
Was it helpful?

Solution 2

Solution:

    @Override
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public List<HoldingDto> getHoldingList()
    {
        List<HoldingDto> holdLst = null;
        try
        {
            String aa = (String) q.getSingleResult();

            CriteriaBuilder cb = em.getCriteriaBuilder();
            CriteriaQuery<HoldingDto> q = cb.createQuery(HoldingDto.class);
            Root<Holding> h = q.from(Holding.class);
            q.select(cb.construct(HoldingDto.class, h.get("holdingId"), h.get("holdingName"), h.get("description"), h.get("savesUserId"), h.get("insertDate"),
                    h.get("updateDate"), h.get("updater"), h.get("RDeleted")));
            holdLst = em.createQuery(q).getResultList();
        } 
        catch(NoResultException e)
        {
            e.printStackTrace();
        }
        catch (Exception e)
        {
            throw new RuntimeException(e);
        }

        return holdLst;
    }

OTHER TIPS

Try executing query "from Holding h". If it will still drop:

ERROR SqlExceptionHelper: An undefined column name was detected.

then it means that you mapped your column names with property names wrong.


You mentioned, that following query works:

Select h.holdingId, h.holdingName, h.description from Holding h

you can track down the column causing exception by adding all columns one by one into select.

Query qry = em.createQuery("from Holding h where h.RDeleted=:arg1");-

shouldn't it be

Query qry = em.createQuery("select h from Holding h where h.RDeleted=:arg1") ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top