小编Shi*_*ami的帖子

如何使用Join定义JPA存储库查询

我想使用带有注释@Query的Jpa存储库进行Join查询.

我有两张桌子:

 table user 
 with iduser,user_name 
Run Code Online (Sandbox Code Playgroud)

和:

 table area 
 with idarea, area_name and iduser
Run Code Online (Sandbox Code Playgroud)

本机查询是:

 SELECT
 u.user_name 
 FROM
  user as u 
  INNER JOIN area as a ON a.iduser = u.iduser
  WHERE
  a.idarea = 4
Run Code Online (Sandbox Code Playgroud)

现在我有一个表Hibernate实体用户和区域

所以我尝试使用UserRespository

@Query(SELECT  u.userName FROM  User u 
  INNER JOIN Area a ON a.idUser = u.idUser
  WHERE
  a.idArea = :idArea)
List<User> findByIdarea(@Param("idArea") Long idArea);
Run Code Online (Sandbox Code Playgroud)

日志说:

意外的标记:

请问有什么想法吗?

我的表实体

#User Table
@Entity
@Table(name="user")
public class User implements Serializable {

    private static final long serialVersionUID = 1L;

    private Long …
Run Code Online (Sandbox Code Playgroud)

java orm jpa repository jpql

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

org.hibernate.type.SerializationException:无法反序列化

我正在使用Hibernate的两个表,我不明白为什么对于特定的查询我有这个问题.我希望有人认识到这个问题.

我有一个表用户

@Entity
@Table(name="user")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
private Long idUser;
private Area area;

//...other get and setter

@OneToOne(fetch=FetchType.EAGER)
@JoinColumn(name="idarea")
public Area getArea() {
return area;
}
}
Run Code Online (Sandbox Code Playgroud)

和一个桌子区域

@Entity
@Table(name = "area")
public class Area implements Serializable {
private static final long serialVersionUID = 1L;

@Id @GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="idarea")
private Long idArea;

@Column(name="area_name")
private String areaName;

@Column(name="time_start")
private LocalTime timeStart;

//...other get and setter

}
Run Code Online (Sandbox Code Playgroud)

LOGS说:

15:27:28,140  INFO DefaultLoadEventListener:160 - Error …
Run Code Online (Sandbox Code Playgroud)

serialization hibernate exception deserialization

9
推荐指数
3
解决办法
5万
查看次数

JAVA - 返回接口列表

我有这个问题,我想只在if块之后返回一个接口和实现类的列表.

public interface Lotto { }

public class LottoImplSecond implements Lotto { }
public class LottoImplFirst implements Lotto { }

public class MyClass {
   public List<Lotto> getLotto(Integer number){
       if(number==1) List<Lotto> listaLotto=new ArrayList<LottoImplFirst>();
       else if(number==2) List<Lotto> listaLotto=new ArrayList<LottoImplSecond>();
   return listaLotto;
}
Run Code Online (Sandbox Code Playgroud)

java interface list implements

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

spring jpa hibernate有更多的数据源

我必须在我的应用程序(spring)中使用两个不同的数据库,使用Hibernate,Jpa.我想直接将不同的表定义到不同的数据源.所以我使用两个不同的持久性单元,我尝试使用

<property name="packagesToScan" value="it.two.app.domain.first" />
Run Code Online (Sandbox Code Playgroud)

<property name="packagesToScan" value="it.two.app.domain.second" />
Run Code Online (Sandbox Code Playgroud)

将不同的表放入不同的包中.但它不起作用.事实上,所有表都是第一个数据源.然后我试着写入持久化XML文件类的名称

 <persistence-unit name="persistenceFirst" transaction-type="RESOURCE_LOCAL">
 <class>it.two.app.domain.first.OneTable</class>
 <exclude-unlisted-classes/>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)

和it.two.app.domain.second.OtherTable

但是当我运行Log时,表'firstDB.other-table'不存在,我用到了services文件中

@PersistenceContext(unitName ="persistenceFirst")
private EntityManager em;
Run Code Online (Sandbox Code Playgroud)

@PersistenceContext(unitName = "persistenceSecond")
EntityManager em;
Run Code Online (Sandbox Code Playgroud)

你有什么想法吗?Thi是数据源XML文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
    http://www.springframework.org/schema/context     http://www.springframework.org/schema/context/spring-context-3.1.xsd">

<!-- first datasource -->
<context:property-placeholder location="classpath:jdbc-first.properties"/>
<bean id="dataSourceFirst"  class="org.apache.commons.dbcp.BasicDataSource"
    p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.databaseurl}"
    p:username="${jdbc.username}" p:password="${jdbc.password}"  />
<!-- second datasource -->      
<context:property-placeholder location="classpath:jdbc-second.properties"/>
<bean id="dataSourceSecond"     class="org.apache.commons.dbcp.BasicDataSource"
    p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.databaseurl}"
    p:username="${jdbc.username}" p:password="${jdbc.password}"  /> …
Run Code Online (Sandbox Code Playgroud)

spring hibernate jpa persistence-unit

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

具有@OneToOne关系的jpa规范

我想将jpa信息库与规范一起使用

现在我有两张桌子

@Entity
@Table(name="user")
public class User implements Serializable {

private static final long serialVersionUID = 1L;

private Long idUser;

private Area area;

@Id @GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="iduser")
public Long getIdUser() {
return idUser;
}
public void setIdUser(Long idUser) {
this.idUser = idUser;
}

@OneToOne(fetch=FetchType.LAZY)
@JoinColumn(name="idarea")
public Area getArea() {
    return area;
}

public void setArea(Area area) {
    this.area = area;
}

}
Run Code Online (Sandbox Code Playgroud)

和面积表

@Entity
@Table(name = "area")
public class Area {

@Id @GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="idarea")
private Long idArea;

@Column(name="area_name")
private String areaName; …
Run Code Online (Sandbox Code Playgroud)

java repository criteria-api jpa-2.0

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

jquery - 选择器类型减去名称

可能重复:
选择具有类的元素,但具有特定标识的元素除外

我必须选择一个表单的类型选择,但我想丢弃一个名称像一个单词的ID.

我有:

 $("select").onchange(function(){
   alert("change");
 });
Run Code Online (Sandbox Code Playgroud)

我想要的类型

$("select minus select with ID like 'noChange'").onchange(function(){
   alert("change");
 });
Run Code Online (Sandbox Code Playgroud)

Tnx tnx

jquery jquery-selectors

0
推荐指数
1
解决办法
348
查看次数