0
DataNucleus將5.1.1:dnSetid的NoSuchMethodErrorDataNucleus將增強運行時錯誤:dnSetid的NoSuchMethodError
@MappedSuperclass
public class Foo {
@Transient
public Long getId() {
...
}
public void setId(Long id) {
...
}
}
@Entity
public class Bar extends Foo {
@Id
@GeneratedValue(strategy=GenerationType.TABLE, generator="gen")
@TableGenerator(name="gen", ...)
public Long getId() {
...
}
}
java.lang.NoSuchMethodError:無類com.example.Bar虛方法dnSetid(龍)
at com.example.Bar.dnCopyKeyFieldsFromObjectId(Unknown Source:15)
at com.example.Bar.dnNewInstance(Unknown Source:10)
at org.datanucleus.enhancer.EnhancementHelper.newInstance(EnhancementHelper.java:178)
at org.datanucleus.state.StateManagerImpl.initialiseForHollow(StateManagerImpl.java:373)
at org.datanucleus.state.ObjectProviderFactoryImpl.newForHollow(ObjectProviderFactoryImpl.java:113)
at org.datanucleus.ExecutionContextImpl.findObject(ExecutionContextImpl.java:3194)
at org.datanucleus.store.rdbms.query.PersistentClassROF.findObjectWithIdAndLoadFields(PersistentClassROF.java:458)
at org.datanucleus.store.rdbms.query.PersistentClassROF.getObject(PersistentClassROF.java:364)
at org.datanucleus.store.rdbms.query.ForwardQueryResult.nextResultSetElement(ForwardQueryResult.java:180)
at org.datanucleus.store.rdbms.query.ForwardQueryResult$QueryResultIterator.next(ForwardQueryResult.java:408)
at org.datanucleus.store.rdbms.query.ForwardQueryResult.processNumberOfResults(ForwardQueryResult.java:136)
at org.datanucleus.store.rdbms.query.ForwardQueryResult.advanceToEndOfResultSet(ForwardQueryResult.java:164)
at org.datanucleus.store.rdbms.query.ForwardQueryResult.closingConnection(ForwardQueryResult.java:290)
at org.datanucleus.store.query.AbstractQueryResult.disconnect(AbstractQueryResult.java:105)
at org.datanucleus.store.rdbms.query.AbstractRDBMSQueryResult.disconnect(AbstractRDBMSQueryResult.java:251)
at org.datanucleus.store.rdbms.query.JPQLQuery$2.managedConnectionPreClose(JPQLQuery.java:654)
at org.datanucleus.store.rdbms.ConnectionFactoryImpl$ManagedConnectionImpl.close(ConnectionFactoryImpl.java:532)
at org.datanucleus.store.connection.AbstractManagedConnection.release(AbstractManagedConnection.java:83)
at org.datanucleus.store.rdbms.ConnectionFactoryImpl$ManagedConnectionImpl.release(ConnectionFactoryImpl.java:371)
at org.datanucleus.store.rdbms.query.JPQLQuery.performExecute(JPQLQuery.java:730)
at org.datanucleus.store.query.Query.executeQuery(Query.java:1966)
at org.datanucleus.store.query.Query.executeWithMap(Query.java:1873)
應通過增強來添加dnSetid。反編譯Bar.class:沒有這樣的方法。它包含dnGetid()和其他方法dn ****。
您的「Foo」方法不是有效的Java Bean簽名。 setXXX接受一個參數。在子類中有一個getter需要一個setter。另外,將屬性標記爲NOT持久不能在繼承樹中重寫。 –
已更正Foo.setId(長),這是錯字。對於子類Bar,setter應該從其父類Foo繼承。瞬態屬性可以在子類中被覆蓋。此代碼適用於EclipseLink編織。 – Sunnyday
不,JPA規範並沒有說你可以突然讓一些屬性在繼承樹下持續下去。同樣徒勞的是,當你已經在超類中持久化時,你不能在子類中創建一個非持久化的屬性。 –