Skip to content

Instantly share code, notes, and snippets.

@stelar7
Last active May 26, 2016 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stelar7/f8414971e8ee130c977346c4baae9d7b to your computer and use it in GitHub Desktop.
Save stelar7/f8414971e8ee130c977346c4baae9d7b to your computer and use it in GitHub Desktop.
Spring-Boot Hibernate MySQL Postgre
Hibernate: create table `profiles` (`user_id` bigint not null, `firstname` varchar(255), `profileImage` longblob, `lastname` varchar(255), `nickname` varchar(255), primary key (`user_id`)) ENGINE=InnoDB
Hibernate: create table `users` (`id` bigint not null auto_increment, `email` varchar(200) not null, `password` varchar(200) not null, `resetToken` varchar(36), `tokenExpires` datetime, `username` varchar(200) not null, primary key (`id`)) ENGINE=InnoDB
Hibernate: alter table `users` add constraint UK_6dotkott2kjsp8vw4d0m25fb7 unique (`email`)
Hibernate: alter table `users` add constraint UK_862ken6gv1xtf7oauhcclgxcc unique (`resetToken`)
Hibernate: alter table `users` add constraint UK_r43af9ap4edm43mmtq01oddj6 unique (`username`)
Hibernate: select user0_.`id` as id1_4_, user0_.`email` as email2_4_, user0_.`password` as password3_4_, user0_.`resetToken` as resetTok4_4_, user0_.`tokenExpires` as tokenExp5_4_, user0_.`username` as username6_4_ from `users` user0_ where user0_.`username`=? or user0_.`email`=?
Hibernate: insert into `users` (`email`, `password`, `resetToken`, `tokenExpires`, `username`) values (?, ?, ?, ?, ?)
Hibernate: insert into `profiles` (`firstname`, `profileImage`, `lastname`, `nickname`, `user_id`) values (?, ?, ?, ?, ?)
Hibernate: create table "profiles" ("user_id" int8 not null, "firstname" varchar(255), "profileImage" oid, "lastname" varchar(255), "nickname" varchar(255), primary key ("user_id"))
Hibernate: create table "users" ("id" bigserial not null, "email" varchar(200) not null, "password" varchar(200) not null, "resetToken" varchar(36), "tokenExpires" timestamp, "username" varchar(200) not null, primary key ("id"))
Hibernate: alter table "users" add constraint UK_6dotkott2kjsp8vw4d0m25fb7 unique ("email")
Hibernate: alter table "users" add constraint UK_862ken6gv1xtf7oauhcclgxcc unique ("resetToken")
Hibernate: alter table "users" add constraint UK_r43af9ap4edm43mmtq01oddj6 unique ("username")
Hibernate: select user0_."id" as id1_4_, user0_."email" as email2_4_, user0_."password" as password3_4_, user0_."resetToken" as resetTok4_4_, user0_."tokenExpires" as tokenExp5_4_, user0_."username" as username6_4_ from "users" user0_ where user0_."username"=? or user0_."email"=?
Hibernate: insert into `users` (`email`, `password`, `resetToken`, `tokenExpires`, `username`) values (?, ?, ?, ?, ?)
o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 42703
o.h.engine.jdbc.spi.SqlExceptionHelper : The column name "id" was not found in this ResultSet.
org.hibernate.exception.SQLGrammarException: could not insert: [lolt.models.data.User];
org.postgresql.util.PSQLException: The column name "id" was not found in this ResultSet.
package lolt.models.data;
import java.util.*;
import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;
import org.hibernate.annotations.*;
import org.hibernate.annotations.Parameter;
import com.fasterxml.jackson.annotation.*;
@Entity
@Table(name = "profiles")
public class Profile
{
@Id
@JsonIgnore
@GeneratedValue(generator = "generator")
@Column(unique = true, nullable = false, name = "user_id")
@GenericGenerator(name = "generator", strategy = "foreign", parameters = @Parameter(name = "property", value = "user"))
Long id;
@PrimaryKeyJoinColumn
@OneToOne(fetch = FetchType.LAZY)
User user;
@Column(name = "firstname")
String firstName;
@Column(name = "nickname")
String nickname;
@Column(name = "lastname")
String lastName;
@Lob
@Column(name = "profileImage")
byte[] image;
/* getters and setters */
}
System.out.println("b");
User start = new User(user.getUsername(), this.bcrypt.encode(user.getPassword()), user.getEmail());
System.out.println("c");
start = this.repo.save(start);
System.out.println("d"); // never reaches this...
package lolt.models.data;
import java.time.*;
import java.util.*;
import javax.persistence.*;
import javax.validation.constraints.*;
import org.hibernate.validator.constraints.*;
import com.fasterxml.jackson.annotation.*;
@Entity
@Table(name = "users")
public class User
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false, unique = true, name = "id")
Long id;
@Length(min = 6, max = 200)
@Column(nullable = false, unique = true, name = "username")
@Size(min = 6, max = 200, message = "Username must be between 6 and 200 chars")
String username;
@Length(min = 6, max = 200)
@Column(nullable = false, name = "password")
@Size(min = 6, max = 200, message = "Password must be between 6 and 200 chars")
String password;
@Length(min = 6, max = 200)
@Column(nullable = false, unique = true, name = "email")
@Size(min = 6, max = 200, message = "Email must be between 6 and 200 chars")
String email;
@Column(unique = true, name = "resetToken", length = 36)
UUID resetToken;
@Column(name = "tokenExpires")
LocalDateTime resetTokenTimeout;
@JsonIgnore
@OneToOne(fetch = FetchType.LAZY, mappedBy = "user", cascade = CascadeType.ALL)
Profile profile;
public User(final String username, final String password, final String email)
{
super();
this.username = username;
this.password = password;
this.email = email;
}
/* getters and setters here */
}
package lolt.repos;
import java.util.*;
import org.springframework.data.jpa.repository.*;
import lolt.models.data.*;
public interface UserRepository extends JpaRepository<User, Long>{}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment