0

I have a Spring Boot app using Spring JPA, hibernate, Derby database, having the following entities and relationships;

@Entity
@Table(name = "users")
public class User implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false, updatable = false)
    private Long id;

    @Column(name = "email", nullable = false, unique = true)
    private String email;

    //bi-directional one-to-one association to Profile
    @OneToOne(cascade={CascadeType.ALL}, orphanRemoval=true)
    @JoinColumn(name="profile_id")
    private Profile profile;

    // ... other fields + getters & setters 
}

And then I have a related Entity shown below;

@Entity
@Table(name = "profiles")
public class Profile implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false, updatable = false)
    private Long id;

    //bi-directional one-to-one association to User
    @OneToOne(mappedBy="profile")
    private User user;

    @Column(name = "first_name", nullable = false)
    private String firstname;

    @Column(name = "last_name", nullable = false)
    private String lastname;

    // ... other fields + getters & setters 
}

Strangely, I noticed that when I run the application and the Database tables get created from the Entities, an email Column also gets created in the profiles Table, even though the Entity has no email field declared.

1. Can someone please first of all explain why this is happening?

2. How do I ensure that the profiles Table does not have an email Column?

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
SourceVisor
  • 1,868
  • 1
  • 27
  • 43
  • Please, enable SQL log and add SQL create table commands. – v.ladynev May 26 '16 at 08:10
  • I've tried both `spring.jpa.show-sql=true` and `spring.jpa.properties.hibernate.show_sql=true` in my **application.properties** file, but none of them shows the SQL queries that are executed when the database Tables are being created from the Entiities... – SourceVisor May 27 '16 at 07:06
  • Please, try this http://stackoverflow.com/a/31249985/3405171 – v.ladynev May 27 '16 at 07:22
  • And, please, check that `application.properties` in the class path. It should be in the root of your build folder. For Eclipse it can be `bin` or `build`. – v.ladynev May 27 '16 at 07:32
  • application.properties is placed correctly in the root... all other properties set in the file are are currently being read appropriately and utilized.... However I will try the suggestion in that link you've provided and see what happens – SourceVisor May 27 '16 at 12:47

0 Answers0