title: what should i do to make sure 'username' unique in table user and avoid duplicate entry '*' for key 2
body: <p>I created two tables, <code>user</code> and <code>journey</code>.</p>
  
  <p>In table <code>user</code>, I added a column named <code>username</code> and made it unique.</p>
  
  <p>In table <code>journey</code>, I reference <code>user_id</code> (the primary key in table <code>user</code>) to <code>foreign key</code> in table <code>journey</code>.</p>
  
  <p>two tabless SQL below:</p>
  
  <pre><code>create table user(
      user_id  INT  auto_increment  PRIMARY KEY,
      username varchar(50) not null,
      avator  varchar(50),
      gender  boolean not null,
      phone varchar(20),
      unique(username)
  );
  
  create table journey(
      id INT auto_increment PRIMARY KEY,
      start varchar(100) not null,
      dest varchar(100) not null,
      time date not null,
      person INT,
      user_id INT not null,
      foreign key(user_id) references user(user_id)
  );
  </code></pre>
  
  <p><code>user</code> and <code>journey</code>'s relation is one-to-many</p>
  
  <p>When I insert new journey data into table <code>journey</code>, hibernate always tried to insert user info into table <code>user</code>, but <code>username</code> is set to be unique, so exception occurs. I am not familiar with databases, what should I do?</p>