Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate问题java.lang.Boolean无法使用JDK 1.7转换为java.lang.String_Java_Hibernate_Java 7_Jdk1.6 - Fatal编程技术网

Hibernate问题java.lang.Boolean无法使用JDK 1.7转换为java.lang.String

Hibernate问题java.lang.Boolean无法使用JDK 1.7转换为java.lang.String,java,hibernate,java-7,jdk1.6,Java,Hibernate,Java 7,Jdk1.6,我面临着Hibernate的问题 使用Hibernate 3.2.6和JDK 1.7.0_21 这个问题是因为JDK与Hibernate版本兼容吗? 这个问题是随机的。我仍然无法找到复制的步骤 2014-07-14 06:09:10,661 [DEBUG] EventExpenseAreaService.getEventSummary:654 - Revenue Value (Hari) --> 1166.15 2014-07-14 06:09:18,665 [ERROR] EventSe

我面临着Hibernate的问题

使用Hibernate 3.2.6和JDK 1.7.0_21

这个问题是因为JDK与Hibernate版本兼容吗?

这个问题是随机的。我仍然无法找到复制的步骤

2014-07-14 06:09:10,661 [DEBUG] EventExpenseAreaService.getEventSummary:654 - Revenue Value (Hari) --> 1166.15
2014-07-14 06:09:18,665 [ERROR] EventSetupService.getEventById:1451 - java.lang.Boolean cannot be cast to java.lang.String
java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String
    at org.hibernate.type.StringType.toString(StringType.java:44)
    at org.hibernate.type.NullableType.nullSafeToString(NullableType.java:93)
    at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:140)
    at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:107)
    at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2002)
    at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2376)
    at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2312)
    at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2612)
    at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:96)
    at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
    at com.sibisoft.northstar.events.service.EventSetupService.getEventById(EventSetupService.java:1441)
    at com.sibisoft.northstar.events.struts.EventAction.load(EventAction.java:1037)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
代码getEventById

public EventDTO getEventById(Integer eventId,boolean logActivity, Session session)throws Exception {

    EventDTO event = null;
    Transaction transaction = null;
    try {

        if (session == null) {
            session = HibernateSessionFactory.getSession();
            if(logActivity){
                transaction = session.beginTransaction();
            }
        }

        event = (EventDTO) super.getByPrimaryKey(EventDTO.class, eventId,session);


        if(transaction!=null){
            transaction.commit();
        }

    } catch (HibernateException e) {
        LOGGER.error(e.getMessage(), e);
        if(transaction!=null){
            transaction.rollback();
        }
        throw e;
    }catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        if(transaction!=null){
            transaction.rollback();
        }
        throw e;
    }

    return event;

}
方法:getByPrimaryKey

protected BaseEventDTO getByPrimaryKey(Class clazz, Integer pk,Session session) throws Exception{

    BaseEventDTO dto = null;
    Transaction tx = null;

    try {

        if (session == null)  {
            session = HibernateSessionFactory.getSession();
        }
        dto = (BaseEventDTO) session.get(clazz, pk);
        return dto;

    }
    catch(Exception e){
        LOGGER.error(e);
        if (tx !=null) {
            tx.rollback();
        }
        throw e;
    }
}

JDK 7已更改
Class.getDeclaredMethods()
,因此无法保证订单

对象映射中可能有一个属性,该属性具有getter方法
String getProperty()
以及间歇性导致问题的
Boolean isproperty()

Hibernate 3
BasicPropertyAccessor.getterMethod(…)
由于未指定JDK 7中的排序,有时会找到
getProperty()
isProperty()
。这混淆了hibernate,它调用了字符串类型属性的布尔类型方法

您需要重命名一个方法才能获得预期的结果


Hibernate论坛上的类似问题:

显示您的代码:com.sibisoft.northstar.events.service.EventSetupService.getEventById()请参阅代码,我在问题中添加了代码