Hibernate NPE при разрешении NamedQuery - PullRequest
0 голосов
/ 10 декабря 2018

Я только что создал несколько аннотированных сущностей и NamedQuery (getCommentsByContainerAndEntityId).Теперь, когда я звоню SessionFactory.openSession(), бросается NPE.Я уже попытался отладить код гибернации немного, и где-то, когда оценивается первое соединение, есть DotNode с нулевым FromReferenceNode (с именем lhs).

Я использую hibernate 5.3.7 в среде OSGi.SessionFactory предоставляется в качестве службы.

Здесь представлены Stacktrace, классы Java и конфигурация гибернации. Полные источники находятся здесь OneDrive Stackoverflow / hibernateNPE

ЭтоNamedQuery в вопросе:

SELECT DISTINCT c FROM comment
LEFT JOIN targetEntity
LEFT JOIN entityType e
WHERE targetEntity.targetIdentifier = :entityIdParameter
AND targetEntity.containerId = :entityContainerIdParameter
AND entityType.targetEntityType = :entityNameParameter
ORDER BY c.authorDate DESC

Это мои сущности:

CommentEntity "comment"

@Id
@Nullable
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

@Column(name = "author", nullable = false)
private String author = "";
@Column(name = "message", nullable = false, columnDefinition = "TEXT")
private String message = "";
@Nullable
@Column(name = "authorDate", nullable = false)
private Date authorDate;
@Nullable
@ManyToOne(targetEntity = CommentTargetEntity.class, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH }, fetch = FetchType.EAGER)
private CommentTargetEntity target;

CommentTargetEntity "targetEntity"

@Id
@Nullable
@Column(name = ID_COLUMN_NAME)
@GenericGenerator(name = "target_hashIdGenerator", strategy = "eu.gemtec.star.comment.db.entity.internal.generators.TargetEntityHashIdGenerator")
@GeneratedValue(generator = "target_hashIdGenerator")
private Long id;

@Nullable
@Column(name = "targetIdentifier", nullable = false)
private Long targetIdentifier;

@Nullable
@Column(name = "targetEntityContainerIdentifier", nullable = false)
private Long targetEntityContainerIdentifier;

@Nullable
@ManyToOne(targetEntity = EntityType.class, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
private EntityType entityType;

EntityType "entityType"

@Id
@Nullable
@Column(name = ID_COLUMN_NAME)
@GenericGenerator(name = "entityType_hashIdGenerator", strategy = "eu.gemtec.star.comment.db.entity.internal.generators.EntityTypeHashIdGenerator")
@GeneratedValue(generator = "entityType_hashIdGenerator")
private Long id;

@Nullable
@Column(name = TARGET_ENTITY_TYPE_COLUMN_NAME, nullable = false, unique = true)
private String targetEntityType;

Мой hibernate.cfg

<hibernate-configuration>
<session-factory>
    <property name="hibernate.check_nullability">false</property>
    <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
    <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
    <property name="hibernate.connection.username">${hibernate_username}</property>
    <property name="hibernate.connection.password">${hibernate_password}</property>
    <property name="hibernate.connection.url">jdbc:postgresql://${hibernate_db_host}/${hibernate_db_name}</property>
    <property name="hibernate.search.autoregister_listeners">false</property>
    <property name="hibernate.hbm2ddl.auto">update</property>
    <property name="hibernate.show_sql">${hibernate_show_sql}</property>

    <mapping class="eu.gemtec.star.comment.db.entity.internal.CommentEntity"/>  
    <mapping class="eu.gemtec.star.comment.db.entity.internal.CommentTargetEntity"/>    
    <mapping class="eu.gemtec.star.comment.db.entity.internal.EntityType"/> 
</session-factory>
</hibernate-configuration>

Stacktrace:

java.lang.NullPointerException
at java.base/java.lang.String.access$100(String.java:123)
at java.base/java.lang.String$CaseInsensitiveComparator.compare(String.java:1235)
at java.base/java.lang.String$CaseInsensitiveComparator.compare(String.java:1229)
at java.base/java.util.TreeMap.getEntryUsingComparator(TreeMap.java:374)
at java.base/java.util.TreeMap.getEntry(TreeMap.java:343)
at java.base/java.util.TreeMap.get(TreeMap.java:277)
at org.hibernate.dialect.function.SQLFunctionRegistry.findSQLFunction(SQLFunctionRegistry.java:45)
at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.findSQLFunction(SessionFactoryHelper.java:385)
at org.hibernate.hql.internal.ast.tree.IdentNode.getDataType(IdentNode.java:366)
at org.hibernate.hql.internal.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:659)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:5002)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1286)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4706)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4174)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2138)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2063)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2063)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:815)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:609)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:313)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:261)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:271)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:191)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:143)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:119)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:153)
at org.hibernate.query.spi.NamedQueryRepository.checkNamedQueries(NamedQueryRepository.java:157)
at org.hibernate.internal.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:574)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:321)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:467)
at org.hibernate.boot.internal.MetadataImpl.buildSessionFactory(MetadataImpl.java:188)
at org.hibernate.osgi.OsgiSessionFactoryService.buildSessionFactory(OsgiSessionFactoryService.java:138)
at org.hibernate.osgi.OsgiSessionFactoryService.getService(OsgiSessionFactoryService.java:83)
at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse$1.run(ServiceFactoryUse.java:212)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse.factoryGetService(ServiceFactoryUse.java:210)
... 49 more
...