小编Ste*_*rnK的帖子

当要求加载惰性字段时,Hibernate 加载所有惰性字段

我在Student和之间有一个 one2one 关系Address。我希望firstNamelastName字段Student被延迟加载。我也想懒惰的address领域。

这些是我的实体类:

@Entity
@Table(name = "students")
public class Student {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  @OneToOne(mappedBy = "student", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
  @LazyToOne(LazyToOneOption.NO_PROXY)
  private Address address;

  @Basic(fetch = FetchType.LAZY)
  @Column(name = "first_name")
  private String firstName;

  @Basic(fetch = FetchType.LAZY)
  @Column(name = "last_name")
  private String lastName;

  // getters and setters
}
Run Code Online (Sandbox Code Playgroud)

地址类:

@Entity
@Table(name = "addresses")
public class Address {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY) …
Run Code Online (Sandbox Code Playgroud)

hibernate lazy-loading

6
推荐指数
1
解决办法
1万
查看次数

如何修复 parser() 已弃用和 setSigningKey(java.security.Key) 已弃用?

这是我在这里面临的错误:

这是我在这里面临的错误

public boolean validateToken(String jwt){
    Jwts.parser().setSigningKey(key).parseClaimsJws(jwt);
    return true;
}
Run Code Online (Sandbox Code Playgroud)

java json spring-boot jwt-simple

6
推荐指数
4
解决办法
2万
查看次数

尝试导入 imblearn 时如何解决“无法从 'sklearn.utils._param_validation' 导入名称 '_MissingValues'”问题?

我正在尝试在安装所需的模块后将 imblearn 导入到我的 python 笔记本中。但是,我收到以下错误:

错误

附加信息:我正在 Visual Studio Code 中使用虚拟环境。

我已确保选择 venv 作为解释器和笔记本内核。我已经重新加载窗口并重新启动内核几次。我还多次卸载并安装了不平衡学习和 scikit-learn,无论是否带有“--upgrade”。我仍然遇到同样的错误。


编辑:错误的完整回溯

{
    "name": "ImportError",
    "message": "cannot import name '_MissingValues' from 'sklearn.utils._param_validation' (c:\\Users\\wen\\OneDrive\\Desktop\\Colab_Notebooks\\.venv\\Lib\\site-packages\\sklearn\\utils\\_param_validation.py)",
    "stack": "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mImportError\u001b[0m                               Traceback (most recent call last)\nCell \u001b[1;32mIn[1], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mimblearn\u001b[39;00m\n\u001b[0;32m      2\u001b[0m \u001b[39m# Data Processing\u001b[39;00m\n\u001b[0;32m      3\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mpandas\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39mpd\u001b[39;00m\n\nFile \u001b[1;32mc:\\Users\\wen\\OneDrive\\Desktop\\Colab_Notebooks\\.venv\\Lib\\site-packages\\imblearn\\__init__.py:52\u001b[0m\n\u001b[0;32m     48\u001b[0m     sys\u001b[39m.\u001b[39mstderr\u001b[39m.\u001b[39mwrite(\u001b[39m\"\u001b[39m\u001b[39mPartial import of imblearn during the build process.\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39m\"\u001b[39m)\n\u001b[0;32m     49\u001b[0m     \u001b[39m# We are not importing the rest of scikit-learn during the build\u001b[39;00m\n\u001b[0;32m     50\u001b[0m     \u001b[39m# process, as it may not be compiled …
Run Code Online (Sandbox Code Playgroud)

python python-3.x scikit-learn imblearn

6
推荐指数
1
解决办法
3万
查看次数

在 Linux/MacOS 上双击执行 C++ 可执行文件

我编写了一个 C++ 软件,该软件需要从其所在的文件夹中读取文件,然后在同一文件夹中写入其他文件。

目前,我通过 shell 导航到复制了可执行文件的文件夹,然后使用./executable_name.

我想通过双击来执行它。如果我这样做,软件告诉我它找不到输入文件,那么就好像它没有在正确的文件夹中执行。

我认为有两种方法:

  1. 继续复制工作文件夹中的可执行文件并告诉它在此文件夹中查找文件。
  2. 创建一个 bash 脚本来调用给定文件夹中的可执行文件(例如应用程序),然后将此脚本复制到工作文件夹中。然后告诉脚本执行该软件,就像它在工作文件夹中一样。
  3. 你可能有更好的想法

无论如何,我不知道该怎么做。

有人可以帮帮我吗?

c++ linux directory macos executable

5
推荐指数
1
解决办法
2749
查看次数

JPA AttributeConverter 是否有可能知道实体正在运行的内容?

AttributeConverter的接口如下:

public interface AttributeConverter<X,Y> {
    public Y convertToDatabaseColumn (X attribute);
    public X convertToEntityAttribute (Y dbData);
}
Run Code Online (Sandbox Code Playgroud)

在我的实现中,我想了解一些有关转换器正在运行的实体和实体字段的信息。例如:此转换器是否应该为应用程序解密该字段?

JAX-RS 的概念@Context非常方便。很好奇 JPA 是否有等效的概念。

java hibernate jpa eclipselink

5
推荐指数
1
解决办法
1519
查看次数

类型不匹配:数字、日期或字符串预期休眠 LocalDate

任务:


该字段在数据库dates中具有类型。date

create table items
(
    id   serial primary key,
    dates date
);
Run Code Online (Sandbox Code Playgroud)

Entity : // 字段“date”,输入“LocalDate”:

@Entity
@Table(name = "items")
public class Item {
    private LocalDate date;

    @Column(name = "dates")
    public LocalDate getDate() {
        return date;
    }
}
Run Code Online (Sandbox Code Playgroud)

用户存储类:

class UserStore {
    private final SessionFactory factory = new Configuration()
            .configure().buildSessionFactory();

    public List<?> findByDate() {
        Session session = factory.openSession();
        session.beginTransaction();
        final String sql = "from Item i where i.date between ?1 and ?2";
        Query query = …
Run Code Online (Sandbox Code Playgroud)

java hibernate jpa mismatch

5
推荐指数
1
解决办法
4033
查看次数

实体映射中序列增量大小设置为[50],而关联数据库序列增量大小为1

我正在尝试在我的第一个 sprinboot 应用程序中配置 postgreSQL 数据库的属性。但是当我运行这个应用程序时,我收到以下错误:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Unsatisfied dependency expressed through method 'requestMappingHandlerAdapter' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.format.support.FormattingConversionService]: Factory method 'mvcConversionService' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeRepository' defined in com.jrp.pma.dao.EmployeeRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: …
Run Code Online (Sandbox Code Playgroud)

java postgresql spring hibernate spring-boot

5
推荐指数
2
解决办法
5201
查看次数

Django datetime TypeError: fromisoformat: 参数必须是 str

Internal Server Error: /api/orders/add/
Traceback (most recent call last):**strong t[enter image description here][1]ext**
  File "C:\Users\kalya\OneDrive\Desktop\my app\myenv\lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
  File "C:\Users\kalya\OneDrive\Desktop\my app\myenv\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response      
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\kalya\OneDrive\Desktop\my app\myenv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view     
    return view_func(*args, **kwargs)
  File "C:\Users\kalya\OneDrive\Desktop\my app\myenv\lib\site-packages\django\views\generic\base.py", line 84, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\Users\kalya\OneDrive\Desktop\my app\myenv\lib\site-packages\rest_framework\views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "C:\Users\kalya\OneDrive\Desktop\my app\myenv\lib\site-packages\rest_framework\views.py", line 469, in handle_exception        
    self.raise_uncaught_exception(exc)
  File "C:\Users\kalya\OneDrive\Desktop\my app\myenv\lib\site-packages\rest_framework\views.py", line 480, in …
Run Code Online (Sandbox Code Playgroud)

django typeerror

5
推荐指数
1
解决办法
2万
查看次数

面临休眠错误:引起:java.lang.ClassNotFoundException:net.bytebuddy.NamingStrategy$SuffixingRandom$BaseNameResolver

在 Eclipse 中运行此代码时出现错误。我已经创建了Student.java文件:

public class Student {
    private int id;
    private String name;
    private String email;
    private int marks;
    
    // getters/setters
}
Run Code Online (Sandbox Code Playgroud)

我已经创建了Student.hbm.xml文件:

<!DOCTYPE hibernate-mapping PUBLIC 
     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
     "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
          
    <hibernate-mapping>
    <class name="bean.Student" table="student">
            <id name="id" column="sid"></id>
            <property name="name"  column="sname"></property>
            <property name="email" column="semail"></property>
            <property name="marks" column="smarks"></property>
    </class>
    </hibernate-mapping>
Run Code Online (Sandbox Code Playgroud)

我已经创建了hibernate.cfg.xml文件:

 <!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
        
    <hibernate-configuration>
    <session-factory>
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@localhost:1521:wind</property>
        <property name="connection.username">localuser</property>
        <property name="connection.password">localuser</property>
        <property name="connection.poolsize">5</property>
            
        <property name="dialect">org.hibernate.dialect.OracleDialect</property>
            
        <mapping resource="resources/student.hbm.xml"/> …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate classnotfoundexception

4
推荐指数
2
解决办法
1万
查看次数

Spring Data 查询无法确定 UUID 参数的数据类型

我有一个Rental具有以下userId字段的实体:

@Column(name = "user_id", updatable = false, nullable = false)
private UUID userId;
Run Code Online (Sandbox Code Playgroud)

我也有一个JpaRepository

public interface RentalRepository extends JpaRepository<Rental, UUID> {

    @Query("FROM Rental r WHERE (:userId IS NULL OR r.userId = :userId) AND (:status IS NULL OR r.status = :status)")
    Page<Rental> findAllUsingFilterUserIdAndStatus(@Param("userId") UUID userId,
                                                   @Param("status") RentalStatus status,
                                                   Pageable pageable);
}
Run Code Online (Sandbox Code Playgroud)

当我将userId作为 null 传递时,出现以下错误:

     org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:280)
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:254) …
Run Code Online (Sandbox Code Playgroud)

sql postgresql spring hibernate spring-data

4
推荐指数
1
解决办法
5261
查看次数