Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "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.dialect">org.hibernate.dialect.MySQLDialect</property>
- <property name="connection.url">jdbc:mysql://localhost:3306/hb4?UseUnicode=true&characterEncoding=utf8</property>
- <property name="hibernate.connection.username">root</property>
- <property name="hibernate.connection.password">2323</property>
- <property name="hibernate.connection.CharSet">utf8</property>
- <property name="hibernate.connection.characterEncoding">utf8</property>
- <property name="hibernate.connection.useUnicode">true</property>
- <property name="hibernate.hbm2ddl.auto">update</property>
- <property name="hibernate.current_session_context_class">thread</property>
- <mapping class="sajjad.htlo.book.Books" />
- <mapping class="sajjad.htlo.customer.Customers" />
- <mapping class="sajjad.htlo.order.Orders" />
- <mapping class="sajjad.htlo.order.OrderItems" />
- </session-factory>
- </hibernate-configuration>
- Caused by: org.hibernate.exception.GenericJDBCException: could not execute statement
- Caused by: java.sql.SQLException: Incorrect string value: 'xD8xADxD8xADxD8xAD...' for column 'password' at row 1
- ...
- @Entity
- public class Customers implements Serializable {
- @Id
- @GeneratedValue
- private Integer cID;
- @Column(nullable = false)
- private String email;
- @Column(nullable = false)
- private String username;
- @Column(nullable = false)
- private String password;
- public Customers() {
- }
- //this is for login
- public Customers(String username, String password) {
- this.username = username;
- this.password = password;
- }
- public Customers(String email, String username, String password) {
- this.email = email;
- this.username = username;
- this.password = password;
- }
- private Session session;
- private Transaction transaction;
- public CustomerDao() {
- }
- public SessionFactory getSessionFactory() {
- Configuration configuration = new Configuration().configure();
- StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().
- applySettings(configuration.getProperties());
- SessionFactory sessionFactory = configuration.buildSessionFactory(builder.build());
- return sessionFactory;
- }
- public Session openSession() {
- session = getSessionFactory().openSession();
- return session;
- }
- public void closeSession() {
- getSession().close();
- }
- public Session openSessionWithTransaction() {
- session = getSessionFactory().openSession();
- transaction = session.beginTransaction();
- return session;
- }
- public void closeSessionWithTransaction() {
- getTransaction().commit();
- getSession().close();
- }
- @Override
- public boolean persist(Customers entity) {
- if(getSession().save(entity).getClass().getName()!=null){
- return true;
- }
- return false;
- }
- @Override
- public void delete(Customers entity) {
- getSession().delete(entity);
- }
- @Override
- public void update(Customers entity) {
- getSession().update(entity);
- }
- @Override
- public void deleteAll() {
- List<Customers> allCustomers = findAll();
- for (Customers eachCustomer : allCustomers) {
- delete(eachCustomer);
- }
- }
- @Override
- public Customers findById(Integer id) {
- Customers foundCustomer = (Customers) getSession().get(Customers.class, id);
- return foundCustomer;
- }
- @Override
- public List<Customers> findAll() {
- List<Customers> allCustomers = getSession().createQuery("from Customers").list();
- return allCustomers;
- }
- public Session getSession() {
- return session;
- }
- public void setSession(Session session) {
- this.session = session;
- }
- public Transaction getTransaction() {
- return transaction;
- }
- public void setTransaction(Transaction transaction) {
- this.transaction = transaction;
- }
- private CustomerDao customerDao;
- public CustomerService() {
- customerDao = new CustomerDao();
- }
- public boolean persistCustomer(Customers entity) {
- boolean result;
- customerDao.openSessionWithTransaction();
- result = customerDao.persist(entity);
- customerDao.closeSessionWithTransaction();
- return result;
- }
- public void deleteCustomer(Integer id) {
- customerDao.openSessionWithTransaction();
- Customers customerToDelete = customerDao.findById(id);
- customerDao.delete(customerToDelete);
- customerDao.closeSessionWithTransaction();
- }
- public void updateCustomer(Customers entity) {
- customerDao.openSessionWithTransaction();
- customerDao.update(entity);
- customerDao.closeSessionWithTransaction();
- }
- public Customers findCustomerById(Integer id) {
- customerDao.openSession();
- Customers foundCustomer = customerDao.findById(id);
- customerDao.closeSession();
- return foundCustomer;
- }
- public List<Customers> findAllCustomers() {
- customerDao.openSession();
- List<Customers> allCustomers = customerDao.findAll();
- customerDao.closeSession();
- return allCustomers;
- }
- public void deleteAllCustomers() {
- customerDao.openSessionWithTransaction();
- customerDao.deleteAll();
- customerDao.closeSessionWithTransaction();
- }
- public CustomerDao customerDao() {
- return customerDao;
- }
- }
- public String registeration() {
- Customers newCustomer = new Customers(email, username, password);
- CustomerService customerService = new CustomerService();
- if (customerService.persistCustomer(newCustomer) == true) {
- return "Succ";
- }
- return "fail";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement