Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Crudepository生成了一个混乱的Sql请求_Java_Mysql_Spring_Intellij Idea_Spring Data Jpa - Fatal编程技术网

Java Crudepository生成了一个混乱的Sql请求

Java Crudepository生成了一个混乱的Sql请求,java,mysql,spring,intellij-idea,spring-data-jpa,Java,Mysql,Spring,Intellij Idea,Spring Data Jpa,我试着在我的工作中使用crudepository。当sql请求出现在我的日志上时,它就是异常的 真正的表是'AllDatabase.AllUserInfo',但生成的sql请求看起来像'all\u user\u info alluresinf0',这是不可用的 我已经上网了,似乎没有人面对我的问题(据我所知)。所以,请有人告诉我,如果我的项目中缺少一些配置 我在Intellij Idea上使用“Spring初始值设定项”,选择“Web”、“JPA”、“MySQL”。这是我的密码 这是我的存储库

我试着在我的工作中使用crudepository。当sql请求出现在我的日志上时,它就是异常的

真正的表是'AllDatabase.AllUserInfo',但生成的sql请求看起来像'all\u user\u info alluresinf0',这是不可用的

我已经上网了,似乎没有人面对我的问题(据我所知)。所以,请有人告诉我,如果我的项目中缺少一些配置

我在Intellij Idea上使用“Spring初始值设定项”,选择“Web”、“JPA”、“MySQL”。这是我的密码

这是我的存储库

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> {

}
这就是我调用save()方法的方式

这是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 

请注意点,即schema.tablename和tablename别名之间的差异


AllUserInfo_f0是AllUserInfo的别名。默认情况下,它在Hibernate中用于多次支持同一表上的查询关系。它不会破坏您的sql。

看看这个似乎与堆栈溢出相关的问题。请避免使用图像来显示代码。如果Hibernate/Spring在您明确指定
@TABLE(name=…)
的情况下仍使用了
all\u user\u info
表名,则这违反了JPA规范。JPA规范明确指出,如果指定了表名,则应使用该表名。。。这不允许提供者在感觉需要下划线时在其中添加下划线符号。问题不在于别名,而在于表名本身。
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);
    }

}
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