Skip to content

Commit

Permalink
Добавил несколько таблиц из бд в hibernate. В остальных нужно поправи…
Browse files Browse the repository at this point in the history
…ть некоторые связи
  • Loading branch information
Maks027 committed Nov 25, 2019
1 parent eb1da7e commit 4948042
Show file tree
Hide file tree
Showing 20 changed files with 356 additions and 58 deletions.
6 changes: 4 additions & 2 deletions .idea/HotDog.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 0 additions & 27 deletions .idea/libraries/Hibernate_5_4_5_5_4_5.xml

This file was deleted.

11 changes: 11 additions & 0 deletions .idea/libraries/mysql_mysql_connector_java_8_0_17.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added lib/mysql-connector-java-8.0.17.jar
Binary file not shown.
Binary file added lib/protobuf-java-3.6.1.jar
Binary file not shown.
26 changes: 15 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,28 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
<version>8.0.17</version>
</dependency>

<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate-version}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.hibernate</groupId>-->
<!-- <artifactId>hibernate-core</artifactId>-->
<!-- <version>${hibernate-version}</version>-->
<!-- </dependency>-->

<!-- for JPA, use hibernate-entitymanager instead of hibernate-core -->
<!-- <dependency>-->
<!-- <groupId>org.hibernate</groupId>-->
<!-- <artifactId>hibernate-entitymanager</artifactId>-->
<!-- <version>${hibernate-version}</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate-version}</version>
<artifactId>hibernate-agroal</artifactId>
<version>5.4.9.Final</version>
<type>pom</type>
</dependency>
</dependencies>



</dependencies>
</project>
2 changes: 2 additions & 0 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import javax.persistence.PrePersist;
import javax.persistence.metamodel.EntityType;

import java.util.Map;
Expand Down Expand Up @@ -44,4 +45,5 @@ public static void main(final String[] args) throws Exception {
session.close();
}
}

}
127 changes: 127 additions & 0 deletions src/main/java/entities/PostsEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package entities;

import javax.persistence.*;
import java.sql.Timestamp;

@Entity
@Table(name = "posts", schema = "hotdog", catalog = "")
public class PostsEntity {
private int idPost;
private String titel;
private Timestamp createTime;
private Timestamp updateTime;
private String content;
private int postLikeCount;
private int postCommentCount;
private UsersEntity usersByUsersId;

@Id
@Column(name = "id_post")
public int getIdPost() {
return idPost;
}

public void setIdPost(int idPost) {
this.idPost = idPost;
}

@Basic
@Column(name = "titel")
public String getTitel() {
return titel;
}

public void setTitel(String titel) {
this.titel = titel;
}

@Basic
@Column(name = "create_time")
public Timestamp getCreateTime() {
return createTime;
}

public void setCreateTime(Timestamp createTime) {
this.createTime = createTime;
}

@Basic
@Column(name = "update_time")
public Timestamp getUpdateTime() {
return updateTime;
}

public void setUpdateTime(Timestamp updateTime) {
this.updateTime = updateTime;
}

@Basic
@Column(name = "content")
public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

@Basic
@Column(name = "post_like_count")
public int getPostLikeCount() {
return postLikeCount;
}

public void setPostLikeCount(int postLikeCount) {
this.postLikeCount = postLikeCount;
}

@Basic
@Column(name = "post_comment_count")
public int getPostCommentCount() {
return postCommentCount;
}

public void setPostCommentCount(int postCommentCount) {
this.postCommentCount = postCommentCount;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

PostsEntity that = (PostsEntity) o;

if (idPost != that.idPost) return false;
if (postLikeCount != that.postLikeCount) return false;
if (postCommentCount != that.postCommentCount) return false;
if (titel != null ? !titel.equals(that.titel) : that.titel != null) return false;
if (createTime != null ? !createTime.equals(that.createTime) : that.createTime != null) return false;
if (updateTime != null ? !updateTime.equals(that.updateTime) : that.updateTime != null) return false;
if (content != null ? !content.equals(that.content) : that.content != null) return false;

return true;
}

@Override
public int hashCode() {
int result = idPost;
result = 31 * result + (titel != null ? titel.hashCode() : 0);
result = 31 * result + (createTime != null ? createTime.hashCode() : 0);
result = 31 * result + (updateTime != null ? updateTime.hashCode() : 0);
result = 31 * result + (content != null ? content.hashCode() : 0);
result = 31 * result + postLikeCount;
result = 31 * result + postCommentCount;
return result;
}

@ManyToOne
@JoinColumn(name = "users_id", referencedColumnName = "id", nullable = false)
public UsersEntity getUsersByUsersId() {
return usersByUsersId;
}

public void setUsersByUsersId(UsersEntity usersByUsersId) {
this.usersByUsersId = usersByUsersId;
}
}
50 changes: 50 additions & 0 deletions src/main/java/entities/TagsEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package entities;

import javax.persistence.*;

@Entity
@Table(name = "tags", schema = "hotdog", catalog = "")
public class TagsEntity {
private int idtags;
private String tags;

@Id
@Column(name = "idtags")
public int getIdtags() {
return idtags;
}

public void setIdtags(int idtags) {
this.idtags = idtags;
}

@Basic
@Column(name = "tags")
public String getTags() {
return tags;
}

public void setTags(String tags) {
this.tags = tags;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

TagsEntity that = (TagsEntity) o;

if (idtags != that.idtags) return false;
if (tags != null ? !tags.equals(that.tags) : that.tags != null) return false;

return true;
}

@Override
public int hashCode() {
int result = idtags;
result = 31 * result + (tags != null ? tags.hashCode() : 0);
return result;
}
}
Loading

0 comments on commit 4948042

Please sign in to comment.