I am trying to build a simple SpringBoot
and Hibernate
app using DAO
and DTO
pattern.
I am trying to save a list of users to the database.
When I am using User
class it works fine, but when I am trying to use DTO CreateUserDto
class I am getting the following error:
"Unknown entity: com.app.sportapp.dto.CreateUserDto; nested exception is org.hibernate.MappingException: Unknown entity: com.app.sportapp.dto.CreateUserDto"
There is a SingleTable
inheritance where Player class
and Coach class
inherit User class
.
User.java
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Getter
@Setter
@Entity(name = "Users")
@ApiModel(description = "All details about user")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "User_Type", discriminatorType= DiscriminatorType.STRING)
public class User implements Seriaalizable{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String firstName;
private String lastName;
private String username;
private String email;
private String password;
private String contactNumber;
}
Player.java
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Getter
@Setter
@Entity(name = "Players")
@DiscriminatorValue(value = "player")
@DiscriminatorOptions(force=true)
public class Player extends User {...}
Coach.java
@Entity(name = "Coaches")
@DiscriminatorValue(value = "coach")
@DiscriminatorOptions(force=true)
public class Coach extends User{
}
And here are DTO's:
CreateUserDto.java
public class CreateUserDto {...}
PlayerDto.java
public class PlayerDto extends CreateUserDto{...}
CoachDto.java
public class CoachDto extends CreateUserDto{
}
As I am very new to DAO
and DTO
pattern from error I am getting I assume that it is expected to have a model with @Entity
called CreateUser
so same name as DTO CreateUserDto
? Or can I have the example what I did to have a User
model and create a new CreateUserDto
?
Thanks!