2

I try to use CrudRepository on my work. And When the sql request appear on my log, It's just abnormal.

This is what it looks like

The real table is 'AllDatabase.AllUserInfo' but the generated sql request look like 'all_user_info alluresinf0_', which is unusable.

I have been all over the internet and nobody seems to face my problem (as far as I know). So please somebody tell me if I'm missing some configuration in my project.

I work on Intellij Idea with 'Spring Initializer' with 'Web' , 'JPA' , 'MySQL' selected. These are my code.

here is my Repository

package com.chuchurest.proj.Repository;

import com.chuchurest.proj.Entity.AllUserInfo;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* Created by slimshady23 on 6/25/2017 AD.
*/

@Transactional
@Repository
public interface UserRepository extends CrudRepository<AllUserInfo,String> {

}

here is The 'AllUserInfo' Entity

package com.chuchurest.proj.Entity;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Id;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import java.io.Serializable;

/**
 * Created by slimshady23 on 6/23/2017 AD.
 */

@Entity
@Table(name = "AllUserInfo")
public class AllUserInfo {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private String Id;

    @Column(name="username")
    private String Username;

    @Column(name="password")
    private String Password;

    @Column(name="email")
    private String Email;

    @Column(name="phone")
    private String Phone;

    @Column(name="rating")
    private Integer Rating;

    @Column(name="skill")
    private Integer Skill;

    @Column(name="description")
    private String Description;

    public String getId() {
        return Id;
    }

    public void setId(String id) {
        Id = id;
    }

    public String getUsername() {
        return Username;
    }

    public void setUsername(String username) {
        Username = username;
    }

    public String getPassword() {
        return Password;
    }

    public void setPassword(String password) {
        Password = password;
    }

    public String getEmail() {
        return Email;
    }

    public void setEmail(String email) {
        Email = email;
    }

    public String getPhone() {
        return Phone;
    }

    public void setPhone(String phone) {
        Phone = phone;
    }

    public Integer getRating() {
        return Rating;
    }

    public void setRating(Integer rating) {
        Rating = rating;
    }

    public Integer getSkill() {
        return Skill;
    }

    public void setSkill(Integer skill) {
        Skill = skill;
    }

    public String getDescription() {
        return Description;
    }

    public void setDescription(String description) {
        Description = description;
    }
}

And this is how I invoke the save() method

package com.chuchurest.proj.Service;

import com.chuchurest.proj.DAO.UserInfoDAO;
import com.chuchurest.proj.Entity.AllUserInfo;
import com.chuchurest.proj.Repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by slimshady23 on 6/24/2017 AD.
 */


@Service
public class AppService {

    @Autowired
    private UserRepository userRepository;


    public void PerformRegister(AllUserInfo userinfo)
    {
        userRepository.save(userinfo);
    }

}

And here is the Application.properties

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/AllDatabase
spring.datasource.username=root
spring.datasource.password= ******


spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
spring.jpa.properties.hibernate.id.new_generator_mappings = false
spring.jpa.properties.hibernate.format_sql = true
spring.jpa.show-sql= true

logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE 
M. Deinum
  • 115,695
  • 22
  • 220
  • 224
17 Chuchu
  • 21
  • 1
  • Take a look at this question that seems related https://stackoverflow.com/questions/39162976/hibernate-naming-strategy-changing-table-names – Paco Abato Jun 25 '17 at 10:47
  • 1
    Welcome to stack overflow. Please avoid using images to show code. – O. Jones Jun 25 '17 at 10:54
  • If Hibernate / Spring came up with a TABLE name of `all_user_info` despite you explicitly specifying `@Table(name=...)` then it is in contravention of the JPA spec. The JPA spec clearly says that if the table name is specified then that is what should be used ... and that doesnt allow a provider putting underscore symbols in there when it feels like it – Neil Stockton Jun 25 '17 at 12:18

1 Answers1

0

Note the dot, the difference between schema.tablename and tablename alias

The AllUserInfo_f0 is an alias for AllUserInfo. It's used in Hibernate by default for supporting query relations on the same table multiple times. It doesn't break your sql.

Jeroen van Dijk-Jun
  • 1,028
  • 10
  • 22