小编blo*_*low的帖子

在spring xml文件中隐藏数据源密码

有一种方法可以在xml spring配置文件中隐藏/加密密码吗?我读过可以使用DataSource的"自定义"子类,但解决方案将密钥保存在与纯文本相同的配置文件中......所以有点无用.

有一种方法可以使用KeyStore吗?例如,从密钥库中读取值.

谢谢大家.

java xml spring keystore password-encryption

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

使用hibernate更新数据库模式

<property name="hibernate.hbm2ddl.auto">update</property>
Run Code Online (Sandbox Code Playgroud)

我可以创建我的数据库模式,它会自动添加属性,约束,键等......但是更新数据库模式呢?如果我从我的实体中删除一些属性,hibernate不会删除它,或者如果我更改了一些约束,hibernate不会触及已创建的约束...

那么,有一种方法可以让hibernate真正更新数据库模式吗?

谢谢.

java hibernate hbm2ddl

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

Spring,@ Transactal和Hibernate Lazy Loading

我正在使用spring + hibernate.我所有的HibernateDAO直接使用sessionFactory.

我有应用层 - >服务层 - > DAO层,并且所有集合都是懒惰加载的.

所以,问题是在应用层(包含GUI/swing)的某个时候我使用服务层方法(包含@Transactional注释)加载实体,我想使用这个对象的lazly属性,但是很明显会话已经关闭.

解决这个问题的最佳方法是什么?

编辑

我尝试使用MethodInterceptor,我的想法是为我的所有实体编写一个AroundAdvice并使用注释,例如:

// Custom annotation, say that session is required for this method
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface SessionRequired {


// An AroundAdvice to intercept method calls
public class SessionInterceptor implements MethodInterceptor {

    public Object invoke(MethodInvocation mi) throws Throwable {
        bool sessionRequired=mi.getMethod().isAnnotationPresent(SessionRequired.class);
        // Begin and commit session only if @SessionRequired
        if(sessionRequired){
            // begin transaction here
        }
        Object ret=mi.proceed();
        if(sessionRequired){
            // commit transaction here
        }
        return ret;
    }
}

// An …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate lazy-loading

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

使NetBeans(ant)为一个项目生成多个jar文件

我有一个netbeans项目,包括两个主要类,一个启动客户端,另一个启动服务器.

我需要创建两个jar文件来包装成两个exe文件,一个用于客户端,一个用于服务器,我该怎么做?

谢谢.

NB:我正在使用蚂蚁.

java netbeans jar

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

为什么hibernate执行两个查询以急切加载@OneToOne双向关联?

我有实体A有一个B实体,而B有一个带有@OneToOne双向关联的A.

现在,当我找到所有A记录时,hibernate在B上执行左外连接的两个查询,如下所示:

select a.id, a.id_b, a.field1, b.id, b.field1 from A as a, B as b left outer join b ON b.id=a.id_b;
select a.id, a.id_b, a.field1, b.id, b.field1 from A as a, B as b left outer join b ON b.id=a.id_b WHERE b.id=?
Run Code Online (Sandbox Code Playgroud)

首先查询加载A和B字段,这没关系,但为什么要执行第二次查询来重新加载A?我认为这个查询加载了B中的A内容,但是这个A显然是包含B的A ......所以它已经加载了第一个查询,是不是真的?

- 编辑 -

实体A:

@Entity
public class A implements Serializable{
    // id and other ecc ecc
    @OneToOne
    @JoinColumn(name="id_b")
    B b;
}
Run Code Online (Sandbox Code Playgroud)

实体B:

@Entity
public class B implements Serializable{
    // id and other ecc ecc
    @OneToOne(mappedBy="b")
    A …
Run Code Online (Sandbox Code Playgroud)

java hibernate jpa one-to-one bidirectional-relation

9
推荐指数
1
解决办法
6181
查看次数

在MPLAB X IDE中使用外部头文件

我有一个包含.h和.c文件的文件夹,我想在我的项目中使用头文件.

我已经使用"添加现有项目"将它们包含在我的项目的"Header Files"文件夹中,但是当我尝试"#include"时,它们编译器(mplabc18\v3.41)说"无法找到文件xyz.h"

那么,如何使用这些文件而不将它们复制到项目文件夹中呢?

include mplab mplab-c18

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

spring,hibernate和声明式事务实现:没有活动事务

我试图使声明式交易工作.

这是我的spring.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:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"

       xsi:schemaLocation=
       "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="url" value="jdbc:h2:tcp://my/db/path" />
        <property name="username" value="username" />
        <property name="password" value="password" />
    </bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="data" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
                <prop key="hibernate.current_session_context_class">thread</prop>
                <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
    </bean>

    <context:component-scan base-package="test" />

    <tx:annotation-driven/>

    <bean id="transactionManager"  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

</beans>
Run Code Online (Sandbox Code Playgroud)

这是我的控制器实现:

//file TestController.java
public interface TestController { …
Run Code Online (Sandbox Code Playgroud)

spring annotations hibernate transactions

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

java swing应用程序中的服务层

我在想我是否真的需要一个服务层.

我正在使用spring + hibernate用于桌面摇摆应用程序,此时我有gui/swing layer-> service layer-> dao layer.我只将spring用于@Transactional支持和IOC注入

最佳实践说我必须编写一个服务来使用我的daos,并将所有事务管理放在服务中.

但我经常意识到,服务层只复制dao方法,例如:

// a DAO example
@Repository
public class CustomerHibernateDAO extends BaseHibernateDAO implements CustomerDAO {

 public List<Customer> findAllCustomerILikeName(String name){
  return getSession()
   .createCriteria(Customer.class)
   .add(Restriction.ilike("name", name))
   .list();
 }
}

// Customer service to use this dao...
@Service
@Transactional
public class CustomerService {

 @Autowired
 CustomerDAO customerDAO;

 // Why i can't call DAO instead the service?
 public List<Customer> getAllCustomersByName(String name){
      return customerDAO.findAllCustomerILikeName(name);
 }

}
Run Code Online (Sandbox Code Playgroud)

这是服务层的一个典型用法... Hibernate是db-agnostic,spring是技术不可知的:所以,我真的需要它吗?

如何管理所有DAO的独特服务类?我认为这可能是一个很好的妥协,或者,这是一种不好的做法?

我知道将@Transactional放在DAO上是一种糟糕的方式,但此时此刻我必须编写仅用于放置@Transactional的服务...

编辑

关于我的应用的更多信息.

我的应用程序是一个管理软件,管理用户注册,产品,订单和其他类似的东西.实际上它包含了很多读取实体 - >编辑 - >保存实体或创建 …

java swing spring hibernate service-layer

8
推荐指数
1
解决办法
2713
查看次数

在Hibernate中实体保存后更新OneToMany列表

我有关系:

// In A.java class
@OneToMany(mappedBy="a", fetch=FetchType.LAZY)
@Cascade(CascadeType.SAVE_UPDATE)
private List<B> bList;

// In B.java class
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="id_a")
@Cascade(CascadeType.SAVE_UPDATE)
private A a;
Run Code Online (Sandbox Code Playgroud)

现在看看这个:

A a=new A();
// setting A

B b=new B();
// setting B
b.setA(a);

session.save(b); // this save b and a obviously
Run Code Online (Sandbox Code Playgroud)

现在的"问题":

  • a.getId() - >当前的新ID OK
  • a.getBList() - >仍为null ...

那么,为什么bList在这种情况下不更新?

我尝试以这种方式重新加载后保存:

A a=new A();
// setting A

B b=new B();
// setting B
b.setA(a);

session.save(b);

A loadedA=(A)session.get(A, a.getId());
Run Code Online (Sandbox Code Playgroud)

但loadedA仍然有一个像b的NULL bList.

我自然会以你的方式避免这个问题:

A a=new A();
// setting A …
Run Code Online (Sandbox Code Playgroud)

java orm hibernate

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

Hibernate,测试集合是否已完全加载

有没有办法测试集合是否已经初始化?try-catch只要?

我有一个函数工作与惰性集合,我需要加载它只有尚未加载.

java collections hibernate lazy-loading

7
推荐指数
1
解决办法
4331
查看次数