【问题标题】:could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet with oauth无法提取结果集; SQL [不适用];嵌套异常是 org.hibernate.exception.SQLGrammarException: could not extract ResultSet with oauth
【发布时间】:2022-04-16 01:04:30
【问题描述】:

我正在使用 java spring boot 进行休息服务。这些表在数据库中正确创建并在本地测试一切正常,但是当我将 .war 挂载到我的 vps 中的 tomcat 中时,失败开始。

向 /oatuh/ 令牌发出 POST 请求以登录会引发异常:

"could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet"

附图:

用户实体:

 @Entity
 @Table(name = "users")
 public class UserEntity implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = -7125479784396028079L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "user_id")
private Long id;

@Column(name = "username", unique = true)
private String username;

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

@Column(name = "email", unique = true)
private String email;

道:

@Repository
public interface UserDao extends JpaRepository<UserEntity, Long>{

@Query("select u from UserEntity u where u.username = ?1")
public UserEntity findByUsername(String username);

}

服务:

@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    UserEntity user = userDao.findByUsername(username);
    System.out.println(user);

    if (user == null) {
        log.error("El usuario no existe en la base de datos.");
        throw new UsernameNotFoundException("Usuario inexistente en la base de datos");
    }

    return new User(user.getUsername(), user.getPassword(), true, true, true, true, null);
 }

【问题讨论】:

  • 您是否尝试过指定架构? @Table(name="users", schema="targetSchemaName")
  • 这是什么数据库?
  • 请提供完整的堆栈跟踪。
  • @Andreas 对不起!我用mysql数据库和方言 MySQL57Dialect spring.jpa.database-platform=org.hibernate.dialect.MySQL57Dialect
  • @bobtang 不,我应该提供什么方案?永远不要为我的实体使用架构

标签: java spring-boot jpa oauth-2.0


【解决方案1】:

解决了!当我的应用程序在 Tomcat 上时,我看不到错误。我尝试了 Postman,但错误是,如果您需要角色,则权限不能为空。

【讨论】:

    【解决方案2】:
    @Column(name = "lastModifiedBy")
    private int lastModifiedBy;
    
    @Column(name = "lastModifedOn")
    private Date lastModifiedOn;
    

    我的代码 lastModifedOn 中有错字,我将其更改为 lastModifiedOn,问题得到永久修复。

    【讨论】:

      【解决方案3】:

      有时会发生在数据库查询中,在查询中,错误的原因是:建表的数据库和配置文件连接的数据库不同,表的数据库地址不同没有仔细检查。

      您必须添加方案,例如:myScheme.myTable。 问候..

      【讨论】:

        猜你喜欢
        • 2017-11-08
        • 1970-01-01
        • 2018-02-04
        • 2015-02-27
        • 1970-01-01
        • 2015-07-01
        • 1970-01-01
        • 2021-09-06
        • 2015-08-03
        相关资源
        最近更新 更多