Home How do I use the jpa/hibernate annotation mapping to Set<Entity> and the Entity is composite primary key
Reply: 0

How do I use the jpa/hibernate annotation mapping to Set<Entity> and the Entity is composite primary key

user1720
1#
user1720 Published in April 26, 2018, 7:54 am
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "users")
@ToString
@Table(name = "users")
@Embeddable
public class User implements UserDetails{
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id",unique=true)
    private Long id;
    @OneToMany
    @Cascade({CascadeType.ALL })
    @JoinTable(name = "users_authorities")
    private Set<SimpleGrantedAuthority> authorities;
}

This is my User.java,and have a porperty private Set<SimpleGrantedAuthority> authorities. I want use jpa/hibernate mapping to another Entity SimpleGrantedAuthority.

@Data
@Entity(name = "authorities")
@Embeddable
@Table(name = "authorities", uniqueConstraints={@UniqueConstraint(columnNames={"authority","username"})})
class SimpleGrantedAuthority implements GrantedAuthority {
    private Long id;
    @Column(name = "authority")
    private String authority;
    @Column(name = "username")
    private String username;
}

This is SimpleGrantedAuthority .java,How do I write the correct annotation to map Set<SimpleGrantedAuthority> authorities; to SimpleGrantedAuthority.javaabove private Set<SimpleGrantedAuthority> authorities;

Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.as.backend.antscience.entity.SimpleGrantedAuthority
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.705292 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO