奇怪的休眠问题

时间:2014-04-29 22:00:05

标签: java mysql sql-server hibernate

在从事学校项目时,我遇到了这个非常奇怪的错误。

为了给出一些上下文,我们使用Java和Hibernate将MySQL数据库转换为SQLServer数据库。它是MLB统计数据库的数据库等。

以下代码位于我的Convert.java主文件中:

Team t
Integer yearId = rs.getInt("yearId");
...
Player p = HibernateUtil.retrievePlayerByNameAndDebutAndBirthCity(firstName + 
               " " + lastName, convertStringToDate(debut), birthCity);              
PlayerSeason plrsn = HibernateUtil.retirevePlayerSeasonByPlayerAndYear(p, yearId);
t.addPlayerSeason(plrsn);

retrievePlayerByNameAndDebutAndBirthCity正确返回一个Player对象。

        Player.java
@Entity(name = "player")
public class Player {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Integer playerId;

@ElementCollection
@CollectionTable(name = "playerposition", joinColumns = @JoinColumn(name = "playerid"))
@Column(name = "position")
@Fetch(FetchMode.JOIN)
Set<String> positions = new HashSet<String>();

@OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.ALL, mappedBy="id.player")
@Fetch(FetchMode.JOIN)
Set<PlayerSeason> seasons = new HashSet<PlayerSeason>();

@Column
String name;
@Column
String nickName;
@Column
Date birthDay;
@Column
Date deathDay;
@Column
String battingHand;
@Column
String throwingHand;
@Column
String birthCity;
@Column
String birthState;
@Column
String college;
@Column
Date firstGame;
@Column
Date lastGame;

但是,retrievePlayerSeasonByPlayerAndYear方法会使程序崩溃。

这里的方法是retrievePlayerSeasonByPlayerAndYear()

 public static PlayerSeason retrievePlayerSeasonByPlayerAndYear(Player p, Integer year){
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction tx = session.getTransaction();
    try {
        tx.begin();
        org.hibernate.Query query; 
        query = session.createQuery("FROM bo.PlayerSeason ps where " + "ps.id.player.id = :pid " + " AND ps.id.year = :y");
        query.setParameter("pid", p.getId());   
        query.setParameter("y", year);
        PlayerSeason toReturn = null;
        if(query.list().size() > 0) //crashes when attempting to execute query.list().size()
            toReturn =  (PlayerSeason) query.list().get(0);
        tx.commit();
        return toReturn;
    } catch (Exception e) {
        tx.rollback();
        e.printStackTrace();
    }
    return null;
}

有什么想法吗?

------- ------- EDIT

我只限于30,000个字符。完整的堆栈跟踪正是我多次重复发布的内容。

----- EDIT --------

我以不正确的顺序发布了堆栈跟踪;现在是对的。上面的序列重复了很多次。

----- ---- EDIT
删除了与错误消息有关的所有先前信息。取消选中&#34;限制控制台输出&#34;选项并获得以下作为堆栈跟踪:

Exception in thread "main" java.lang.StackOverflowError
at java.util.logging.Level.intValue(Unknown Source)
at java.util.logging.Logger.isLoggable(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSReader.reset(IOBuffer.java:4929)
at com.microsoft.sqlserver.jdbc.ServerDTVImpl.skipValue(dtv.java:2357)
at com.microsoft.sqlserver.jdbc.DTV.skipValue(dtv.java:104)
at com.microsoft.sqlserver.jdbc.Column.skipValue(Column.java:86)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.skipColumns(SQLServerResultSet.java:156)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.loadColumn(SQLServerResultSet.java:743)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getterGetColumn(SQLServerResultSet.java:2062)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getValue(SQLServerResultSet.java:2082)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getValue(SQLServerResultSet.java:2067)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getInt(SQLServerResultSet.java:2319)
at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$2.doExtract(IntegerTypeDescriptor.java:74)
at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:267)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:263)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:253)

其余的跟踪重复下面的模式:

at org.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:190)
at org.hibernate.type.ComponentType.hydrate(ComponentType.java:637)
at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:331)
at org.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:190)
at org.hibernate.type.ComponentType.hydrate(ComponentType.java:637)
at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.readIdentifierHydratedState(EntityReferenceInitializerImpl.java:117)
at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.hydrateIdentifier(EntityReferenceInitializerImpl.java:96)
at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.readRow(AbstractRowReader.java:89)
at org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails$EntityLoaderRowReader.readRow(EntityLoadQueryDetails.java:255)
at org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:129)
at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:138)
at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:102)
at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:186)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4126)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:502)
at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:467)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:212)
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:274)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:150)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1070)
at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:989)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:716)
at org.hibernate.type.EntityType.resolve(EntityType.java:502)
at org.hibernate.type.ComponentType.resolve(ComponentType.java:662)
at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:331)

0 个答案:

没有答案