1. Создать пользователя
2. Найти пользователя
3. Удалить пользователя
0. Выход
2
Введите имя пользователя: asd
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Пользователь получен из базы данных. Имя: asd пароль: 123456Seven
1. Создать пользователя
2. Найти пользователя
3. Удалить пользователя
0. Выход
package entity;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;
/**
*
* @author seostella.com
*/
@Entity
public class Article {
private long id;
private String title;
private String message;
private User user;
private Set<Category> categories;
public Article(String title, String message, User user) {
this.title = title;
this.message = message;
this.user = user;
this.categories = new HashSet<Category>();
}
public Article() {
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@ManyToOne
@JoinColumn(name = "user_id")
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
@ManyToMany(mappedBy = "articles")
public Set<Category> getCategories() {
return categories;
}
public void setCategories(Set<Category> categories) {
this.categories = categories;
}
@Id
@GeneratedValue
protected long getId() {
return id;
}
protected void setId(long id) {
this.id = id;
}
}
package entity;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;
/**
*
* @author seostella.com
*/
@Entity
public class Category {
private long id;
private String title;
private Set<Article> articles = new HashSet<Article>();
public Category() {
}
public Category(String title) {
this.title = title;
this.articles = new HashSet<Article>();
}
@ManyToMany
@JoinTable(name="category_article")
public Set<Article> getArticles() {
return articles;
}
void setArticles(Set<Article> adverts) {
this.articles = adverts;
}
public void addArticles(Article advert) {
getArticles().add(advert);
}
@Column(unique=true)
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Id
@GeneratedValue
protected long getId() {
return id;
}
protected void setId(long id) {
this.id = id;
}
}
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test2</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="connection.password">root</property>
<!-- <property name="show_sql">true</property>-->
<!-- <mapping jar="hibernate-mappings.jar"/> -->
<mapping class="entity.Article"/>
<mapping class="entity.Category"/>
<mapping class="entity.User"/>
</session-factory>
</hibernate-configuration>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>HibernateForLittle</groupId>
<artifactId>HibernateForLittle</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>jboss</id>
<url>http://repository.jboss.org/maven2</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.9.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>3.1.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>3.2.4.GA</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId> org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<version>0.8.1</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>mainServlet</servlet-name>
<servlet-class>com.login.servlet.MainServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>mainServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Но если именно мой то придется подаждать