valchkou / cassandra-driver-mapping

JPA addon for DataStax Java Driver for Cassandra
57 stars 24 forks source link

Kotlin entities are not created on get #83

Closed kojiba closed 7 years ago

kojiba commented 7 years ago

code for bean


class PartitionUserKey(email: String, id: UUID) {
    var email: String = email
    var id: UUID = id
}

class CompositeUserKey(email: String, userId: Long, id: UUID = UUID.randomUUID()) {
    @EmbeddedId
    var key: PartitionUserKey = PartitionUserKey(email = email, id = id)
    var userId = userId

}

@Table(name = "UserBean",
        indexes = arrayOf(
                Index(name = "userbean_email_idx", columnList = "email")
        )
)
public class UserBean(userId: Long,
                      aboutMeInfo: String,
                      firstName: String,
                      lastName: String,
                      email: String,
                      passwordHash: String) : BaseBean() {

    @EmbeddedId
    var key: CompositeUserKey = CompositeUserKey(email, userId)

    var createdDate: Date = Date()

    var firstName: String = firstName
    var lastName: String = lastName
    var profilePicUrl: String = ""
    var aboutMeInfo: String = aboutMeInfo

    var passwordHash: String = passwordHash

    var postsCount: Long = 0
    var messagesCount: Long = 0
    var chatsCount: Long = 0
    var loginCount: Long = 0
    var activeSessionCount: Long = 0

    var hasLikesTotal: Long = 0
    var hasCommentsTotal: Long = 0
    var hasRepostsTotal: Long = 0

    var friendsIds: MutableList<String> = mutableListOf<String>()
    var followingFriendsIds: MutableList<String> = mutableListOf<String>() // that u requested
    var followersFriendsIds: MutableList<String> = mutableListOf<String>()

    val email: String
        @Transient
        get() = key.key.email

    val userId: Long
        @Transient
        get() = key.userId

    override var id: UUID
        @Transient
        get() = key.key.id
        @Transient
        set(value) {
            key.key.id = value
        }
}

code for get

// get Entity Metadata
            val emeta = EntityTypeParser.getEntityMetadata(UserBean::class.java)

            // get field metadata by property/field name
            val fmeta = emeta.getFieldMetadata("email")

            // build query.
            val query = QueryBuilder.select().all()
                    .from(Connection.keyspaceName, emeta.tableName).where(

                    eq(fmeta.columnName, email))

            // run query
            val result = Connection.mappingSession.getByQuery(UserBean::class.java, query)

in result gives arraylist with nulls, but not objects

kojiba commented 7 years ago

my fuckup, class have not public empty constructor i.e. UserBean() not created