Hello everyone in advance I have a problem with my one to one connection when I try to log in to the "user" I get this error
what i need is a one to one connection that does not have to be persistent that means a user can have a player but does not have to have it and the other way around
Since in my case the Minecraft server is supposed to fill the player table and the website fills the users so that they can be connected.
2020-07-27 23:06:12,537 DEBUG [http-nio-8080-exec-2] nirvanacw.de.demo.user.UserServiceImpl: --> getUserByEmail email=Test#gmx.de
2020-07-27 23:06:12,550 WARN [http-nio-8080-exec-2] org.hibernate.engine.jdbc.spi.SqlExceptionHelper: SQL Error: 42122, SQLState: 42S22
2020-07-27 23:06:12,550 ERROR [http-nio-8080-exec-2] org.hibernate.engine.jdbc.spi.SqlExceptionHelper: Feld "player0_.player" nicht gefunden
Column "player0_.player" not found; SQL statement:
select player0_.id as id1_2_1_, player0_.banned as banned2_2_1_, player0_.first_joined as first_jo3_2_1_, player0_.ip_address as ip_addre4_2_1_, player0_.last_joined as last_joi5_2_1_, player0_.player as player8_2_1_, player0_.player_name as player_n6_2_1_, player0_.uuid as uuid7_2_1_, user1_.id as id1_3_0_, user1_.active as active2_3_0_, user1_.created as created3_3_0_, user1_.email as email4_3_0_, user1_.first_name as first_na5_3_0_, user1_.last_name as last_nam6_3_0_, user1_.password as password7_3_0_, user1_.reset_password as reset_pa8_3_0_, user1_.roles as roles9_3_0_, user1_.updated as updated10_3_0_, user1_.username as usernam11_3_0_ from player player0_ left outer join user user1_ on player0_.player=user1_.id where player0_.player=? [42122-200]
2020-07-27 23:06:12,558 ERROR [http-nio-8080-exec-2] org.springframework.security.oauth2.provider.endpoint.TokenEndpoint: Handling error: InternalAuthenticationServiceException, could not prepare statement; SQL [select player0_.id as id1_2_1_, player0_.banned as banned2_2_1_, player0_.first_joined as first_jo3_2_1_, player0_.ip_address as ip_addre4_2_1_, player0_.last_joined as last_joi5_2_1_, player0_.player as player8_2_1_, player0_.player_name as player_n6_2_1_, player0_.uuid as uuid7_2_1_, user1_.id as id1_3_0_, user1_.active as active2_3_0_, user1_.created as created3_3_0_, user1_.email as email4_3_0_, user1_.first_name as first_na5_3_0_, user1_.last_name as last_nam6_3_0_, user1_.password as password7_3_0_, user1_.reset_password as reset_pa8_3_0_, user1_.roles as roles9_3_0_, user1_.updated as updated10_3_0_, user1_.username as usernam11_3_0_ from player player0_ left outer join user user1_ on player0_.player=user1_.id where player0_.player=?]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement
org.springframework.security.authentication.InternalAuthenticationServiceException: could not prepare statement; SQL [select player0_.id as id1_2_1_, player0_.banned as banned2_2_1_, player0_.first_joined as first_jo3_2_1_, player0_.ip_address as ip_addre4_2_1_, player0_.last_joined as last_joi5_2_1_, player0_.player as player8_2_1_, player0_.player_name as player_n6_2_1_, player0_.uuid as uuid7_2_1_, user1_.id as id1_3_0_, user1_.active as active2_3_0_, user1_.created as created3_3_0_, user1_.email as email4_3_0_, user1_.first_name as first_na5_3_0_, user1_.last_name as last_nam6_3_0_, user1_.password as password7_3_0_, user1_.reset_password as reset_pa8_3_0_, user1_.roles as roles9_3_0_, user1_.updated as updated10_3_0_, user1_.username as usernam11_3_0_ from player player0_ left outer join user user1_ on player0_.player=user1_.id where player0_.player=?]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement
User Entity :
package nirvanacw.de.demo.user;
import nirvanacw.de.demo.player.Player;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
import javax.validation.constraints.Email;
import java.time.ZonedDateTime;
import java.util.Objects;
#Entity
#Table(name = "user")
public class User {
#Id
#GeneratedValue(strategy = GenerationType.AUTO, generator = "native")
#GenericGenerator(name = "native", strategy = "native")
#Column(name = "id", updatable = false, nullable = false)
private Long id;
#Email
#Column(name = "email")
private String email;
#Column(name ="username")
private String username;
#Column(name ="password")
private String password;
#Column(name ="first_name")
private String firstName;
#Column(name ="last_name")
private String lastName;
#OneToOne(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Player player;
#Column(name ="reset_password")
private boolean resetPassword;
#Column(name ="roles")
private String roles;
#Column(name ="active")
private boolean active;
#Column(name = "created")
private ZonedDateTime created;
#Column(name = "updated")
private ZonedDateTime updated;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public boolean isResetPassword() {
return resetPassword;
}
public void setResetPassword(boolean resetPassword) {
this.resetPassword = resetPassword;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getRoles() {
return roles;
}
public void setRoles(String roles) {
this.roles = roles;
}
public boolean getActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public Player getPlayer() {
return player;
}
public void setPlayer(Player player) {
this.player = player;
}
#PrePersist
public void onPrePersist() {
this.created = ZonedDateTime.now();
}
#PreUpdate
public void onPreUpdate() {
this.updated = ZonedDateTime.now();
}
#Override
public String toString() {
return "User{" +
"id=" + id +
", email='" + email + '\'' +
", username='" + username + '\'' +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", player=" + player +
", resetPassword=" + resetPassword +
", roles='" + roles + '\'' +
", active=" + active +
", created=" + created +
", updated=" + updated +
'}';
}
#Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
return resetPassword == user.resetPassword &&
active == user.active &&
Objects.equals(id, user.id) &&
Objects.equals(email, user.email) &&
Objects.equals(username, user.username) &&
Objects.equals(password, user.password) &&
Objects.equals(firstName, user.firstName) &&
Objects.equals(lastName, user.lastName) &&
Objects.equals(player, user.player) &&
Objects.equals(roles, user.roles) &&
Objects.equals(created, user.created) &&
Objects.equals(updated, user.updated);
}
#Override
public int hashCode() {
return Objects.hash(id, email, username, password, firstName, lastName, player, resetPassword, roles, active, created, updated);
}
}
Player Entity :
import java.sql.Timestamp;
import java.util.Objects;
import java.util.UUID;
#Entity
#Table(name = "player")
public class Player {
#Id
#GeneratedValue(strategy = GenerationType.AUTO, generator = "native")
#GenericGenerator(name = "native", strategy = "native")
#Column(name = "id", updatable = false, nullable = false)
private Long id;
#Column(name = "uuid")
private UUID uuid;
#OneToOne
#JoinColumn(name = "player")
private User user;
#Length(max = 16)
#Column(name = "player_name")
private String userName;
#Column(name = "banned")
private boolean banned;
#Column(name = "first_joined")
private Timestamp firstJoined;
#Column(name = "last_joined")
private Timestamp lastJoined;
#Column(name = "ip_address")
private String ipAddress;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public UUID getUuid() {
return uuid;
}
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public boolean isBanned() {
return banned;
}
public void setBanned(boolean banned) {
this.banned = banned;
}
public Timestamp getFirstJoined() {
return firstJoined;
}
public void setFirstJoined(Timestamp firstJoined) {
this.firstJoined = firstJoined;
}
public Timestamp getLastJoined() {
return lastJoined;
}
public void setLastJoined(Timestamp lastJoined) {
this.lastJoined = lastJoined;
}
public String getIpAddress() {
return ipAddress;
}
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
#Override
public String toString() {
return "Player{" +
"id=" + id +
", uuid=" + uuid +
", user=" + user +
", userName='" + userName + '\'' +
", banned=" + banned +
", firstJoined=" + firstJoined +
", lastJoined=" + lastJoined +
", ipAddress='" + ipAddress + '\'' +
'}';
}
#Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Player player = (Player) o;
return banned == player.banned &&
Objects.equals(id, player.id) &&
Objects.equals(uuid, player.uuid) &&
Objects.equals(user, player.user) &&
Objects.equals(userName, player.userName) &&
Objects.equals(firstJoined, player.firstJoined) &&
Objects.equals(lastJoined, player.lastJoined) &&
Objects.equals(ipAddress, player.ipAddress);
}
#Override
public int hashCode() {
return Objects.hash(id, uuid, user, userName, banned, firstJoined, lastJoined, ipAddress);
}
}
Flyway user :
Create TABLE user(
id bigint NOT NULL AUTO_INCREMENT,
email character varying(256),
username character varying(256),
password character varying(256),
reset_password boolean,
first_name character varying(50),
last_name character varying(50),
gender character varying(10),
player_id character varying(17),
active boolean,
roles character varying(40),
created TIMESTAMP,
updated TIMESTAMP,
CONSTRAINT PK_account_account_id PRIMARY KEY (id)
);
Player Flyway :
CREATE TABLE player(
id bigint NOT NULL AUTO_INCREMENT,
uuid char(36) NOT NULL,
player_name character varying (16),
user_id bigint,
banned boolean,
first_joined timestamp,
last_joined timestamp,
ip_address character varying (15),
CONSTRAINT PK_player_player_id PRIMARY KEY (id),
CONSTRAINT FK_player_user_id_user_id FOREIGN KEY (user_id) REFERENCES user(id)
);
The error is quite clear
Column "player0_.player" not found;
the player table does not have a player column
the error is here:
#OneToOne
#JoinColumn(name = "player")
private User user;
change to:
#OneToOne
#JoinColumn(name = "user_id")
private User user;
It is the column by which the join with user is established.
As a recommendation, there are configuration parameters for the JPA implementation to validate the correct modeling of the entities without the need for queries, find out how to activate it with the implementation you have chosen.
Related
I have an issue with userId in Habits table. it is a foreign key from id in Users Table. but I keep getting the error "Unhandled Exception: Null check operator used on a null value " from AddHabitDialogController class.
obviously userId should never be null. where is the issue? how can I solve it?
if more code is needed you can check : https://github.com/sarasoltan/habit_tracker
Users Table:
class UsersTable {
static const String tableName = 'Users';
static const String id = 'id';
static const String email = 'email';
static const String createQuery = '''
CREATE TABLE IF NOT EXISTS $tableName (
$id integer primary key autoincrement,
$email text not null unique);''';
#override
String toString() => 'Person, ID: $id, email: $email';
#override
bool operator ==(covariant Users other) => id == other.id;
#override
int get hashCode => id.hashCode;
}
Habits table:
class HabitsTable {
static const String tableName = 'Habits';
static const String id = 'id';
static const String userId = 'userId';
static const String text = 'text';
static const String emoji = 'emoji';
static const String period = 'period';
static const String startPeriod = 'startPeriod';
static const String createQuery = '''
CREATE TABLE IF NOT EXISTS $tableName (
$id integer primary key autoincrement,
$userId integer not null,
$text text not null,
$emoji text not null,
$period text not null,
$startPeriod integer,
FOREIGN Key($userId) REFERENCES ${UsersTable.tableName}(${UsersTable.id}));''';
User model class:
class Users {
late final int id;
late String email;
Users({
required this.id,
required this.email,
});
Users.fromDb(Map<String, dynamic> map) {
id = map[UsersTable.id];
email = map[UsersTable.email];
}
}
Habit model class:
class Habit {
late final int id;
late final int userId;
late String text;
late String emoji;
late final List<int> period;
late final DateTime? startPeriod;
Habit(
{
//required this.id,
required this.userId,
required this.text,
required this.emoji,
required this.period,
this.startPeriod});
Habit.fromDb(Map<String, dynamic> map) {
id = map[HabitsTable.id] as int;
userId = map[HabitsTable.userId] as int;
text = map[HabitsTable.text] as String;
emoji = map[HabitsTable.emoji];
period = (jsonDecode(map[HabitsTable.period]) as List<dynamic>)
.map((e) => e as int)
.toList();
if (map[HabitsTable.startPeriod] != null) {
startPeriod =
DateTime.fromMillisecondsSinceEpoch(map[HabitsTable.startPeriod]);
} else {
startPeriod = null;
}
}
Map<String, dynamic> toDb() {
Users? owner;
return {
//HabitsTable.id: id,
HabitsTable.userId: owner!.id,
HabitsTable.text: text,
HabitsTable.emoji: emoji,
HabitsTable.period: jsonEncode(period),
HabitsTable.startPeriod: startPeriod?.millisecondsSinceEpoch
};
}
AddHabitDialogController(error):
class AddHabitDialogController {
Users? owner;
//final user = FirebaseAuth.instance.currentUser;
//String get owneruserId => AuthService.firebase().currentUser!.id;
final List<bool> period = [true, true, true, true, true, true, true];
int? id;
int? userId;
String? emoji;
String? text;
StartPeriod startPeriod = StartPeriod.none;
final StreamController<bool> _addBtnEnabledCtrl = StreamController();
Stream<bool> get addBtnEnabled => _addBtnEnabledCtrl.stream;
final StreamController<StartPeriod> _selectedStartPeriodCtrl =
StreamController();
Stream<StartPeriod> get selectedStartPeriod =>
_selectedStartPeriodCtrl.stream;
final StreamController<bool> _loadingCtrl = StreamController();
Stream<bool> get loading => _loadingCtrl.stream;
void changePeriodValue(int index, bool newValue) {
period[index] = newValue;
_updateAddBtnEnabledState();
}
void changeTextValue(String newValue) {
text = newValue;
_updateAddBtnEnabledState();
}
void changeEmojiValue(String newEmoji) {
emoji = newEmoji;
_updateAddBtnEnabledState();
}
void changeStartPeriod(StartPeriod newValue) {
startPeriod = newValue;
_selectedStartPeriodCtrl.add(startPeriod);
}
Future<void> addHabit(BuildContext context) async {
_loadingCtrl.add(true);
final dataService = GetIt.I.get<DataService>();
final List<int> forPeriod = [];
for (int i = 0; i < period.length; i++) {
if (period[i]) {
forPeriod.add(i + 1);
}
}
final habit = Habit(
//id: id!,
userId: owner!.id, //error from here
emoji: emoji!,
text: text!,
period: forPeriod,
startPeriod: _calculateStartPeriodDateTime());
await dataService.addHabit(habit);
_loadingCtrl.add(false);
Navigator.of(context).pop();
}
void _updateAddBtnEnabledState() {
_addBtnEnabledCtrl.add((text?.isNotEmpty ?? false) &&
(emoji?.isNotEmpty ?? false) &&
period.where((e) => e).isNotEmpty);
}
DateTime? _calculateStartPeriodDateTime() {
final now = DateTime.now();
switch (startPeriod) {
case StartPeriod.today:
return DateTime(now.year, now.month, now.day);
case StartPeriod.thisMonth:
return DateTime(now.year, now.month);
case StartPeriod.thisYear:
return DateTime(now.year);
case StartPeriod.none:
default:
return null;
}
}
void dispose() {
_addBtnEnabledCtrl.close();
_loadingCtrl.close();
_selectedStartPeriodCtrl.close();
}
}
enum StartPeriod { none, today, thisMonth, thisYear }
Because the local variable of AddHabitDialogController owner can't be referenced before it is declared
class AddHabitDialogController {
Users? owner; // -> you did not assign this owner?
I have been following online tutorials for MVC but have hit a snag with updating.
Have used a updateStudent() method in the controller and pass in the id, but inside the updateStudent() I have alot of optionals.
Trying to figure out how to call the api and select the optional from within the method I want it to use
Any help is appreciated
Thanks.
Controller....
public class StudentController {
public final StudentService studentService;
#Autowired
public StudentController(StudentService studentService) {
this.studentService=studentService;
}
#PutMapping(path="/updateme/{id}")
public void updateStudent(#PathVariable ("id") UUID id,#RequestBody Student student) {
studentService.updateStudent(id, student);
}
StudentService...
#Service
public class StudentService {
private final StudentDao studentDao;
//constructor
public StudentService(#Qualifier("postgres3")StudentDao studentDao) {
this.studentDao=studentDao;
}
#PutMapping
public void updateStudent(UUID id, Student student) {
Optional.ofNullable(student.getChapterProgress())
.filter(cp -> !StringUtils.isEmpty(cp))
.ifPresent(cp -> studentDao.updateChapterProgress(id, cp));
Optional.ofNullable(student.getAvgTestScore())
.filter(avg -> !StringUtils.isEmpty(avg))
.ifPresent(avg -> studentDao.updateAvgTestScore(id, avg));
Optional.ofNullable(student.getChap1Score())
.filter(c1 -> !StringUtils.isEmpty(c1))
.ifPresent(c1 -> studentDao.updateChap1Score(id, c1));
Optional.ofNullable(student.getChap2Score())
.filter(c2 -> !StringUtils.isEmpty(c2))
.ifPresent(c2 -> studentDao.updateChap2Score(id, c2));
Optional.ofNullable(student.getChap3Score())
.filter(c3 -> !StringUtils.isEmpty(c3))
.ifPresent(c3 -> studentDao.updateChap3Score(id, c3));
Optional.ofNullable(student.getChap4Score())
.filter(c4 -> !StringUtils.isEmpty(c4))
.ifPresent(c4 -> studentDao.updateChap4Score(id, c4));
Optional.ofNullable(student.getChap5Score())
.filter(c5 -> !StringUtils.isEmpty(c5))
.ifPresent(c5 -> studentDao.updateChap5Score(id, c5));
Optional.ofNullable(student.getChap6Score())
.filter(c6 -> !StringUtils.isEmpty(c6))
.ifPresent(c6 -> studentDao.updateChap6Score(id, c6));
}
StudentDataAccessService...
#Repository("postgres3")
public class StudentDataAccessService implements StudentDao {
private JdbcTemplate jdbcTemplate;
#Autowired
public StudentDataAccessService(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate= jdbcTemplate;
}
#Override
public int updateChapterProgress(UUID id, Integer chapterprogress) {
String sql = "UPDATE student SET chapterprogress = ? WHERE id = ?";
return jdbcTemplate.update(sql, chapterprogress, id);
}
#Override
public int updateAvgTestScore(UUID id, Double avg) {
String sql = "UPDATE student SET avgtestscore = ? WHERE id = ?";
return jdbcTemplate.update(sql, avg, id);
}
#Override
public int updateChap1Score(UUID id, Double chap1Score) {
String sql = "UPDATE student SET chap1score = ? WHERE id = ?";
return jdbcTemplate.update(sql, chap1Score, id);
}
#Override
public int updateChap2Score(UUID id, Double chap2Score) {
String sql = "UPDATE student SET chap2score = ? WHERE id = ?";
return jdbcTemplate.update(sql, chap2Score, id);
}
#Override
public int updateChap3Score(UUID id, Double chap3Score) {
String sql = "UPDATE student SET chap3score = ? WHERE id = ?";
return jdbcTemplate.update(sql, chap3Score, id);
}
#Override
public int updateChap4Score(UUID id, Double chap4Score) {
String sql = "UPDATE student SET chap4score = ? WHERE id = ?";
return jdbcTemplate.update(sql, chap4Score, id);
}
#Override
public int updateChap5Score(UUID id, Double chap5Score) {
String sql = "UPDATE student SET chap5score = ? WHERE id = ?";
return jdbcTemplate.update(sql, chap5Score, id);
}
#Override
public int updateChap6Score(UUID id, Double chap6Score) {
String sql = "UPDATE student SET chap6score = ? WHERE id = ?";
return jdbcTemplate.update(sql, chap6Score, id);
}
#Override
public int updateStudentById(UUID id, Student student) {
return 0;
}
StudentDao...
public interface StudentDao {
int updateStudentById(UUID id,Student student);
int updateChapterProgress(UUID id, Integer chapterprogress);
int updateAvgTestScore(UUID id, Double avg);
int updateChap1Score(UUID id, Double chap1Score);
int updateChap2Score(UUID id, Double chap2Score);
int updateChap3Score(UUID id, Double chap3Score);
int updateChap4Score(UUID id, Double chap4Score);
int updateChap5Score(UUID id, Double chap5Score);
int updateChap6Score(UUID id, Double chap6Score);
Ended up assigning each update to its own method call in the controller, thanks
In the restbucks project, an order has a private list of line items. I can't figure out how this field is exposed via rest api when getting a single order. It has no public getter or anything. Is it the mixins?
#Data, #NoArgsConstructor, #AllArgsConstructor, #EqualsAndHashCode are Lombok annotations, that are used to auto-generate a boilerplate code.
#Data
#Entity
#NoArgsConstructor(force = true)
#AllArgsConstructor
#EqualsAndHashCode(callSuper = false)
public class LineItem extends AbstractEntity {
private final String name;
private final int quantity;
private final Milk milk;
private final Size size;
private final MonetaryAmount price;
public LineItem(String name, MonetaryAmount price) {
this(name, 1, Milk.SEMI, Size.LARGE, price);
}
}
You can compare this code with delomboked one (welcome to Lombok-funs club )):
#Entity
public class LineItem extends AbstractEntity {
private final String name;
private final int quantity;
private final Milk milk;
private final Size size;
private final MonetaryAmount price;
public LineItem(String name, MonetaryAmount price) {
this(name, 1, Milk.SEMI, Size.LARGE, price);
}
public LineItem(String name, int quantity, Milk milk, Size size, MonetaryAmount price) {
this.name = name;
this.quantity = quantity;
this.milk = milk;
this.size = size;
this.price = price;
}
public LineItem() {
this.name = null;
this.quantity = 0;
this.milk = null;
this.size = null;
this.price = null;
}
public String getName() {
return this.name;
}
public int getQuantity() {
return this.quantity;
}
public Milk getMilk() {
return this.milk;
}
public Size getSize() {
return this.size;
}
public MonetaryAmount getPrice() {
return this.price;
}
public String toString() {
return "LineItem(name=" + this.getName() + ", quantity=" + this.getQuantity() + ", milk=" + this.getMilk() + ", size=" + this.getSize() + ", price=" + this.getPrice() + ")";
}
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof LineItem)) return false;
final LineItem other = (LineItem) o;
if (!other.canEqual((Object) this)) return false;
final Object this$name = this.getName();
final Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
if (this.getQuantity() != other.getQuantity()) return false;
final Object this$milk = this.getMilk();
final Object other$milk = other.getMilk();
if (this$milk == null ? other$milk != null : !this$milk.equals(other$milk)) return false;
final Object this$size = this.getSize();
final Object other$size = other.getSize();
if (this$size == null ? other$size != null : !this$size.equals(other$size)) return false;
final Object this$price = this.getPrice();
final Object other$price = other.getPrice();
if (this$price == null ? other$price != null : !this$price.equals(other$price)) return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $name = this.getName();
result = result * PRIME + ($name == null ? 43 : $name.hashCode());
result = result * PRIME + this.getQuantity();
final Object $milk = this.getMilk();
result = result * PRIME + ($milk == null ? 43 : $milk.hashCode());
final Object $size = this.getSize();
result = result * PRIME + ($size == null ? 43 : $size.hashCode());
final Object $price = this.getPrice();
result = result * PRIME + ($price == null ? 43 : $price.hashCode());
return result;
}
protected boolean canEqual(Object other) {
return other instanceof LineItem;
}
}
I have a problem when performing a query in an HQL.
ORM
Persona
#Entity
#Table(name = "persona")
#Inheritance(strategy = InheritanceType.JOINED)
#DynamicUpdate
#SelectBeforeUpdate(value = false)
#SelectBeforeUpdate(value = false)
#NamedQueries({
#NamedQuery(name = "PersonasByRfc", query = "FROM Persona p WHERE p.rfc = :rfc "),
#NamedQuery(name = "PersonasPorTipoPersona", query = "FROM Persona p WHERE p.tipoPersona = :tipoPersona "),
#NamedQuery(name = "PersonaByClienteId", query = " SELECT c.persona FROM Cliente c WHERE c.clienteId = :clienteId "),
#NamedQuery(name = "PersonaMoralActiva", query = "SELECT c.persona FROM Cliente c WHERE c.persona.regimenFiscal = 'MORAL' AND c.estatus = 'ACTIVO' ")
})
public class Persona extends CommonBusinessProperties {
private static final long serialVersionUID = 2846894501470704239L;
private Long personaId;
private CatTipoPersona tipoPersona;
private String descripcionTipoPersona;
private String nombres;
private String apellidoMaterno;
private String apellidoPaterno;
private RegimenFiscal regimenFiscal;
private Nacionalidad nacionalidad;
private String rfc;
private String curp;
private Genero genero;
private Date fechaNacimiento;
private Boolean esCliente;
private Boolean esContratante;
private Boolean esPagador;
private Boolean esMontoPagar;
private BigDecimal montoPagar;
private Boolean esPorcentajePagar;
private String porcentajePagar;
private String origenPersona;
private String parentesco;
private Parentesco tranParentesco;
private Cliente cliente;
private ExpedientePersona expedientePersona;
private List<Domicilio> domicilios = new ArrayList<>(0);
private List<Telefono> telefonos = new ArrayList<>(0);
private List<Correo> correos = new ArrayList<>(0);
/**
* Constructor <br>
* Crea una nueva instancia de Persona. <br>
*
* #author Orlando Adrián Ramos Galván (oramos#legosoft.com.mx, orlandoa.ramos#outlook.com)<br>
*/
public Persona() {
super();
}
/**
* Constructor <br>
* Crea una nueva instancia de Persona. <br>
*
* #param personaId
* #author Orlando Adrián Ramos Galván (oramos#legosoft.com.mx, orlandoa.ramos#outlook.com)<br>
*/
public Persona(Long personaId) {
super();
this.personaId = personaId;
}
/**
* Constructor <br>
* Crea una nueva instancia de Persona. <br>
*
* #param personaBuilder
* #author Orlando Adrián Ramos Galván (oramos#legosoft.com.mx, orlandoa.ramos#outlook.com)<br>
*/
public Persona(PersonaBuilder personaBuilder) {
this.tipoPersona = personaBuilder.getTipoPersona();
this.descripcionTipoPersona = personaBuilder.getDescripcionTipoPersona();
this.nombres = personaBuilder.getNombresORazonSocial();
this.apellidoMaterno = personaBuilder.getApellidoMaterno();
this.apellidoPaterno = personaBuilder.getApellidoPaterno();
this.setRegimenFiscal(personaBuilder.getRegimenFiscal());
this.setNacionalidad(personaBuilder.getNacionalidad());
this.setRfc(personaBuilder.getRfc());
this.curp = personaBuilder.getCurp();
this.genero = personaBuilder.getGenero();
this.fechaNacimiento = personaBuilder.getFechaNacimiento();
this.esCliente = personaBuilder.getEsCliente();
this.esContratante = personaBuilder.getEsContratante();
this.esPagador = personaBuilder.getEsPagador();
this.esMontoPagar = personaBuilder.getEsMontoPagar();
this.montoPagar = personaBuilder.getMontoPagar();
this.esPorcentajePagar = personaBuilder.getEsPorcentajePagar();
this.porcentajePagar = personaBuilder.getPorcentajePagar();
this.domicilios = personaBuilder.getDomicilios();
this.telefonos = personaBuilder.getTelefonos();
this.correos = personaBuilder.getCorreos();
}
#Id
#GeneratedValue(strategy = IDENTITY)
#Column(name = "persona_id", unique = true, nullable = false, updatable = false)
public Long getPersonaId() {
return this.personaId;
}
public void setPersonaId(Long personaId) {
this.personaId = personaId;
}
#ManyToOne(fetch = FetchType.EAGER, targetEntity = CatTipoPersona.class)
#JoinColumn(name = "tipo_persona_id")
#Fetch(FetchMode.SELECT)
public CatTipoPersona getTipoPersona() {
return this.tipoPersona;
}
public void setTipoPersona(CatTipoPersona tipoPersona) {
this.tipoPersona = tipoPersona;
}
#Column(name = "tipo_persona", length = 50)
public String getDescripcionTipoPersona() {
return this.descripcionTipoPersona;
}
public void setDescripcionTipoPersona(String tipoPersona) {
this.descripcionTipoPersona = tipoPersona;
}
#Column(name = "origen_persona", length = 50)
public String getOrigenPersona() {
return this.origenPersona;
}
#Column(name = "nombres", length = 100)
public String getNombresORazonSocial() {
return this.nombres;
}
public void setNombresORazonSocial(String nombres) {
this.nombres = nombres;
}
#Column(name = "apellido_materno", length = 100)
public String getApellidoMaterno() {
return this.apellidoMaterno;
}
public void setApellidoMaterno(String apellidoMaterno) {
this.apellidoMaterno = apellidoMaterno;
}
#Column(name = "apellido_paterno", length = 100)
public String getApellidoPaterno() {
return this.apellidoPaterno;
}
public void setApellidoPaterno(String apellidoPaterno) {
this.apellidoPaterno = apellidoPaterno;
}
#Transient
public String getNombreCompleto() {
return this.nombres + " " + this.apellidoMaterno + " " + this.apellidoPaterno;
}
#Column(name = "regimen_fiscal", length = 100)
#Enumerated(EnumType.STRING)
public RegimenFiscal getRegimenFiscal() {
return this.regimenFiscal;
}
public void setRegimenFiscal(RegimenFiscal regimenFiscal) {
this.regimenFiscal = regimenFiscal;
}
#Column(name = "nacionalidad", length = 100)
#Enumerated(EnumType.STRING)
public Nacionalidad getNacionalidad() {
return this.nacionalidad;
}
public void setNacionalidad(Nacionalidad nacionalidad) {
this.nacionalidad = nacionalidad;
}
#Column(name = "rfc", length = 13)
public String getRfc() {
return this.rfc;
}
public void setRfc(String rfc) {
this.rfc = rfc;
}
#Column(name = "curp", length = 45)
public String getCurp() {
return this.curp;
}
public void setCurp(String curp) {
this.curp = curp;
}
#Column(name = "genero", length = 1)
#Convert(converter = GeneroConverter.class)
public Genero getGenero() {
return this.genero;
}
public void setGenero(Genero genero) {
this.genero = genero;
}
#Temporal(TemporalType.DATE)
#Column(name = "fecha_nacimiento", length = 10)
public Date getFechaNacimiento() {
return this.fechaNacimiento;
}
public void setFechaNacimiento(Date fechaNacimiento) {
this.fechaNacimiento = fechaNacimiento;
}
#Column(name = "es_cliente")
public Boolean isCliente() {
return this.esCliente;
}
public void setIsCliente(Boolean esCliente) {
this.esCliente = esCliente;
}
#Column(name = "es_contratante")
public Boolean esContratante() {
return this.esContratante;
}
public void setEsContratante(Boolean esContratante) {
this.esContratante = esContratante;
}
#Column(name = "es_pagador")
public Boolean isEsPagador() {
return this.esPagador;
}
public void setEsPagador(Boolean esPagador) {
this.esPagador = esPagador;
}
#Column(name = "es_monto_pagar")
public Boolean getEsMontoPagar() {
return this.esMontoPagar;
}
public void setEsMontoPagar(Boolean esMontoPagar) {
this.esMontoPagar = esMontoPagar;
}
#Column(name = "monto_pagar", precision = 16, scale = 4)
public BigDecimal getMontoPagar() {
return this.montoPagar;
}
public void setMontoPagar(BigDecimal montoPagar) {
this.montoPagar = montoPagar;
}
#Column(name = "es_porcentaje_pagar")
public Boolean getEsPorcentajePagar() {
return this.esPorcentajePagar;
}
public void setEsPorcentajePagar(Boolean esPorcentajePagar) {
this.esPorcentajePagar = esPorcentajePagar;
}
#Column(name = "porcentaje_pagar", length = 6)
public String getPorcentajePagar() {
return this.porcentajePagar;
}
public void setPorcentajePagar(String porcentajePagar) {
this.porcentajePagar = porcentajePagar;
}
public void setOrigenPersona(String origenPersona) {
this.origenPersona = origenPersona;
}
#OneToOne(fetch = FetchType.EAGER, mappedBy = "persona", targetEntity = ExpedientePersona.class, optional = true)
protected ExpedientePersona getExpedientePersona() {
return this.expedientePersona;
}
protected void setExpedientePersona(ExpedientePersona expedientePersonas) {
this.expedientePersona = expedientePersonas;
}
/**
* #return parentesco
*/
#Column(name = "parentesco", length = 50)
public String getParentesco() {
return parentesco;
}
/**
* #param parentesco
*/
public void setParentesco(String parentesco) {
this.parentesco = parentesco;
}
#OneToOne(fetch = FetchType.EAGER, mappedBy = "persona", targetEntity = Cliente.class, cascade = {
CascadeType.MERGE, CascadeType.DETACH })
#Fetch(FetchMode.SELECT)
public Cliente getCliente() {
return this.cliente;
}
public void setCliente(Cliente cliente) {
this.cliente = cliente;
}
/**
* #return si la persona esta relacionada al contratante y es una familiar este campo idnica que
* parentesco tienen.
*/
#Transient
public Parentesco getTranParentesco() {
return tranParentesco;
}
/**
* #param tranParentesco
*/
public void setTranParentesco(Parentesco tranParentesco) {
this.tranParentesco = tranParentesco;
}
#OneToMany(fetch = FetchType.EAGER, mappedBy = "persona", targetEntity = Domicilio.class, cascade = {
CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH })
#Fetch(FetchMode.SELECT)
#OrderBy
protected List<Domicilio> getDomicilios() {
return this.domicilios;
}
protected void setDomicilios(List<Domicilio> domicilios) {
this.domicilios = domicilios;
}
#OneToMany(fetch = FetchType.EAGER, mappedBy = "persona", targetEntity = Telefono.class, cascade = {
CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH })
#Fetch(FetchMode.SELECT)
#OrderBy
protected List<Telefono> getTelefonos() {
return this.telefonos;
}
protected void setTelefonos(List<Telefono> telefonos) {
this.telefonos = telefonos;
}
#OneToMany(fetch = FetchType.EAGER, mappedBy = "persona", targetEntity = Correo.class, cascade = {
CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH })
#Fetch(FetchMode.SELECT)
#OrderBy
protected List<Correo> getCorreos() {
return this.correos;
}
protected void setCorreos(List<Correo> correos) {
this.correos = correos;
}
}
My Phone table has a composite primary of phone number and id. id is also a foreign key to the Student table.
I am seeing the below error when I run it.
23:30:28,228 ERROR SqlExceptionHelper:147 - Column 'id' cannot be null
org.hibernate.exception.ConstraintViolationException: could not execute statement
Schema:
Table: student
Columns:
id (PK)
fName
lName
mName
Table: Phone
Columns:
phoneNumber (PK)
color
id(PK)(FK references to Student id)
Student.java
import java.io.Serializable;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
#Entity
#SuppressWarnings("serial")
public class Student implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String fName;
private String lName;
private String mname;
#OneToMany(cascade = CascadeType.ALL)
#JoinColumn(name = "id")
private Set<Phone> phones;
/**
* #return the fName
*/
public String getfName() {
return fName;
}
/**
* #return the id
*/
public int getId() {
return id;
}
/**
* #return the lName
*/
public String getlName() {
return lName;
}
/**
* #return the mname
*/
public String getMname() {
return mname;
}
/**
* #return the phones
*/
public Set<Phone> getPhones() {
return phones;
}
/**
* #param fName
* the fName to set
*/
public void setfName(final String fName) {
this.fName = fName;
}
/**
* #param id
* the id to set
*/
public void setId(final int id) {
this.id = id;
}
/**
* #param lName
* the lName to set
*/
public void setlName(final String lName) {
this.lName = lName;
}
/**
* #param mname
* the mname to set
*/
public void setMname(final String mname) {
this.mname = mname;
}
/**
* #param phones
* the phones to set
*/
public void setPhones(final Set<Phone> phones) {
this.phones = phones;
}
}
Phone.java
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
#IdClass(PhonePK.class)
#Entity
#SuppressWarnings("serial")
public class Phone implements Serializable {
#Id
private String phoneNumber;
// #Id
// #ManyToOne
// #JoinColumn(name = "id", insertable = false, updatable = false)
// private String id;
#Id
#ManyToOne
#JoinColumn(name = "id", insertable = false, updatable = false)
private Student student;
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
private String color;
/**
* #return the color
*/
public String getColor() {
return color;
}
/**
* #return the phoneNumber
*/
public String getPhoneNumber() {
return phoneNumber;
}
/**
* #return the student
*/
public Student getStudent() {
return student;
}
/**
* #param color
* the color to set
*/
public void setColor(final String color) {
this.color = color;
}
/**
* #param phoneNumber
* the phoneNumber to set
*/
public void setPhoneNumber(final String phoneNumber) {
this.phoneNumber = phoneNumber;
}
/**
* #param student
* the student to set
*/
public void setStudent(final Student student) {
this.student = student;
}
}
PhonePK.java
import java.io.Serializable;
#SuppressWarnings("serial")
public class PhonePK implements Serializable {
private String phoneNumber;
//private String id;
private Student student;
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
/**
* #return the phoneNumber
*/
public String getPhoneNumber() {
return phoneNumber;
}
/**
* #return the student
*/
public Student getStudent() {
return student;
}
/**
* #param phoneNumber
* the phoneNumber to set
*/
public void setPhoneNumber(final String phoneNumber) {
this.phoneNumber = phoneNumber;
}
/**
* #param student
* the student to set
*/
public void setStudent(final Student student) {
this.student = student;
}
#Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
PhonePK other = (PhonePK) obj;
if (phoneNumber == null) {
if (other.phoneNumber != null) {
return false;
}
} else if (!phoneNumber.equals(other.phoneNumber)) {
return false;
}
if (student == null) {
if (other.student != null) {
return false;
}
} else if (!student.equals(other.student)) {
return false;
}
// if (id == null) {
// if (other.id != null) {
// return false;
// }
// } else if (!id.equals(other.id)) {
// return false;
// }
return true;
}
#Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((phoneNumber == null) ? 0 : phoneNumber.hashCode());
result = prime * result + ((student == null) ? 0 : student.hashCode());
// result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
}
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">pwd</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.pool_size">1</property>
<property name="hbm2ddl.auto">create</property>
</session-factory>
</hibernate-configuration>
Main.java
import java.util.LinkedHashSet;
import java.util.Set;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class Main {
public static void main(final String args[]) {
Configuration configuration = new Configuration();
Transaction transaction = null;
configuration.addAnnotatedClass(Student.class);
configuration.addAnnotatedClass(Phone.class);
configuration.addAnnotatedClass(PhonePK.class);
configuration.configure("hibernate.cfg.xml");
SessionFactory sessionFactory = configuration.buildSessionFactory();
System.out.println("Session Factory!!!!" + sessionFactory);
Session session = sessionFactory.openSession();
Student student = new Student();
student.setfName("Bob");
student.setlName("Buster");
Set<Phone> phones = new LinkedHashSet<Phone>();
Phone ph1 = new Phone();
ph1.setColor("Black");
ph1.setPhoneNumber("1111111111");
Phone ph2 = new Phone();
ph2.setColor("Blue");
ph2.setPhoneNumber("2222222222");
phones.add(ph1);
phones.add(ph2);
student.setPhones(phones);
try {
transaction = session.beginTransaction();
session.save(student);
transaction.commit();
} catch (HibernateException e) {
transaction.rollback();
e.printStackTrace();
} finally {
session.close();
}
}
}
Console output:
23:30:24,291 INFO SchemaExport:343 - HHH000227: Running hbm2ddl schema export
23:30:24,296 DEBUG SQL:104 - alter table Phone drop foreign key
FK_aoj0eivd0ap3drxnoyk4xj10q
23:30:25,613 DEBUG SQL:104 - drop table if exists Phone
23:30:25,967 DEBUG SQL:104 - drop table if exists Student
23:30:26,230 DEBUG SQL:104 - create table Phone (phoneNumber varchar(255) not null,
color varchar(255), id integer not null, primary key (phoneNumber, id))
23:30:26,731 DEBUG SQL:104 - create table Student (id integer not null auto_increment,
fName varchar(255), lName varchar(255), mname varchar(255), primary key (id))
23:30:26,792 DEBUG SQL:104 - alter table Phone add index FK_aoj0eivd0ap3drxnoyk4xj10q
(id), add constraint FK_aoj0eivd0ap3drxnoyk4xj10q foreign key (id) references Student
(id)
23:30:27,352 INFO SchemaExport:405 - HHH000230: Schema export complete
Session Factory!!!!org.hibernate.internal.SessionFactoryImpl#548997d1
23:30:27,823 DEBUG SQL:104 - insert into Student (fName, lName, mname) values (?, ?, ?)
23:30:27,886 TRACE BasicBinder:84 - binding parameter [1] as [VARCHAR] - Bob
23:30:27,887 TRACE BasicBinder:84 - binding parameter [2] as [VARCHAR] - Buster
23:30:27,888 TRACE BasicBinder:72 - binding parameter [3] as [VARCHAR] - <null>
23:30:28,005 DEBUG SQL:104 - select phone_.phoneNumber, phone_.id, phone_.color as
color2_0_ from Phone phone_ where phone_.phoneNumber=? and phone_.id=?
23:30:28,009 TRACE BasicBinder:84 - binding parameter [1] as [VARCHAR] - 1111111111
23:30:28,010 TRACE BasicBinder:72 - binding parameter [2] as [INTEGER] - <null>
23:30:28,102 DEBUG SQL:104 - select phone_.phoneNumber, phone_.id, phone_.color as
color2_0_ from Phone phone_ where phone_.phoneNumber=? and phone_.id=?
23:30:28,103 TRACE BasicBinder:84 - binding parameter [1] as [VARCHAR] - 2222222222
23:30:28,104 TRACE BasicBinder:72 - binding parameter [2] as [INTEGER] - <null>
23:30:28,222 DEBUG SQL:104 - insert into Phone (color, phoneNumber, id) values (?, ?,
?)
23:30:28,223 TRACE BasicBinder:84 - binding parameter [1] as [VARCHAR] - Black
23:30:28,224 TRACE BasicBinder:84 - binding parameter [2] as [VARCHAR] - 1111111111
23:30:28,224 TRACE BasicBinder:72 - binding parameter [3] as [INTEGER] - <null>
23:30:28,227 WARN SqlExceptionHelper:145 - SQL Error: 1048, SQLState: 23000
23:30:28,228 ERROR SqlExceptionHelper:147 - Column 'id' cannot be null
org.hibernate.exception.ConstraintViolationException: could not execute statement
at
org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert
(SQLExceptionTypeDelegate.java:74)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert
(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert
(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert
(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate
(ResultSetReturnImpl.java:136)
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch
(NonBatchingBatch.java:58)
at org.hibernate.persister.entity.AbstractEntityPersister.insert
(AbstractEntityPersister.java:3067)
at org.hibernate.persister.entity.AbstractEntityPersister.insert
(AbstractEntityPersister.java:3509)
at org.hibernate.action.internal.EntityInsertAction.execute
(EntityInsertAction.java:88)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:377)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:369)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:286)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions
(AbstractFlushingEventListener.java:339)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush
(DefaultFlushEventListener.java:52)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1234)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:404)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.
beforeTransactionCommit
(JdbcTransaction.java:101)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit
(AbstractTransactionImpl.java:175)
at Main.main(Main.java:49)
Caused by:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:
Column 'id' cannot be null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1041)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate
(ResultSetReturnImpl.java:133)
... 14 more
23:30:28,323 INFO AbstractBatchImpl:195 - HHH000010:
On release of batch it still contained JDBC statements
you can create embeddale Primary key class.
#Embeddable
public class Phone_pk implements Serializable{
#ManyToOne(targetEntity=Student.class)
#JoinColumn(name="id", referencedColumnName="id")
#ForeignKey(name="Student_Phone_FK")
private Student student;
private String phoneNumber;
}
And use this as primary key in your phone class
#EmbeddedId
private Phone_pk PK;