Reputation: 2052
I'm using a users
table, defined as:
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique user id.',
`username` varchar(50) NOT NULL COMMENT 'username(unique identifier for each user.)',
`password` text NOT NULL COMMENT 'password encrypted with salt.',
`phone` varchar(20) DEFAULT NULL COMMENT 'phone number(phone number should be unique for each user.)',
`email` varchar(70) DEFAULT NULL COMMENT 'e-mail(e-mail should be unique for each user.)',
`status` enum('ACTIVE','LOCKED','DELETED') NOT NULL COMMENT 'user account status.',
`isDeleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'boolean flag deleting whether the user is deleted or not.',
`created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date and time of user creation.',
`updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'Date and time when the user was last updated.',
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`,`phone`,`email`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8
Also, a custom User
POJO, that looks something like:
@Table(name = "users")
public class User {
@Column(name = "id")
private Integer id;
@Column(name = "username")
private String userName;
@Column(name = "phone")
private String userPhone;
@Column(name = "email")
private String userEmail;
@Column(name = "password")
private String password;
// Getters and Setters omitted for brevity
}
Now, when I simply fetch()
the record, it works fine:
UsersRecord user = new DSLContextFactory("demo").getDSLContext()
.selectFrom(USERS)
.where(USERS.USERNAME.eq("james"))
.fetchOne();
System.out.println(user);
But, if I try fetchOneInto(User.class)
, it only lodges the id field to User
:
User user = new DSLContextFactory("demo").getDSLContext()
.selectFrom(USERS)
.where(USERS.USERNAME.eq("james"))
.fetchOneInto(User.class);
System.out.println(user);
Now, the above snippet returns this:
[User{id=3, userName='null', userPhone='null', userEmail='null'}]
I have not the slightest clue what's going on here. Some help would be greatly appreciated!
I'm using JOOQ 3.15.0
Upvotes: 1
Views: 471
Reputation: 2052
Turns out the culprit here was the usage of jakarta.persistence-api
. Switching to javax.persistence-api
made things all fine and dandy.
Upvotes: 1