My User model
@Entity
@Table(name="users")
data class User(
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = -1,
@Column(unique=true)
val username: String) : Serializable
Two records in the database
The query is fine.
[2018-02-23T14:32:07.066+0100] [Payara 4.1] [FINE] [] [org.eclipse.persistence.session./file:/Users/youri/Downloads/payara41/glassfish/domains/domain1/applications/Kwetter-1.0-SNAPSHOT/WEB-INF/classes/_kwetter.sql] [tid: _ThreadID=28 _ThreadName=http-thread-pool::http-listener-1(4)] [timeMillis: 1519392727066] [levelValue: 500] [[ SELECT ID, USERNAME FROM users]]
But it outputs two empty objects, instead of two User objects
[{},{}]
Abstract Dao where I use the Entity Manager
@Stateless
abstract class Abstract<T : Serializable> {
@PersistenceContext
private lateinit var entityManager: EntityManager
abstract fun getEntityClass(): Class<T>
open fun find(id: Long): T {
return entityManager.find(getEntityClass(), id)
}
// this returns the weird two empty objects
open fun all(): List<T> {
val builder = entityManager.criteriaBuilder
val c = builder.createQuery(getEntityClass())
c.from(getEntityClass())
val query = entityManager.createQuery(c)
return query.resultList
}
}
item::class
? They don't seem to be of typeUser
. – Salem