我有一个表,图像数据存储在MySQL数据库的blob字段中.有没有办法只使用SQL将这些图像导出到文件系统上的文件?图像应命名为{imageId} .jpg
我知道用Java或其他方法很容易做到这一点,但只用SQL脚本就可以了吗?
我刚刚在Spring配置中配置了一个属性占位符
<context:property-placeholder location="classpath:/config/config.properties" />
Run Code Online (Sandbox Code Playgroud)
如果我使用此配置运行应用程序一切正常.但是,如果我尝试运行单元测试,则测试无法加载,ApplicationContext因为a FileNotFoundException.如果我尝试从Eclipse运行测试以及通过maven运行测试时会发生这种情况.
我也尝试PropertyPlaceholderConfigurer直接配置相同的结果.
看起来文件不在类路径位置,即使测试类是用注释的
@ContextConfiguration("classpath:/config/spring-config.xml")
Run Code Online (Sandbox Code Playgroud)
这些文件位于同一文件夹中,它会找到xml配置.
我已经尝试使用不同的路径:classpath:config/config.properties没有classpath前缀,都没有用.文件前缀的绝对路径有效,但这不是一个好的解决方案.
有没有办法让属性占位符与测试一起工作?我已经找到的一个解决方案是通过在xml中提供默认属性来覆盖位置.还有其他解决方案吗?或者我是唯一有这个问题的人?
我的测试类看起来像这样:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:/config/spring-config.xml")
@Transactional
public class JpaImageDaoTest {
@Autowired
private ImageDataDao imageDataDao;
@Test
public void testFindById() {
Image anImage = new Image();
anImage.setData(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
imageDao.save(anImage);
Image image = imageDao.findById(imageData.getId());
assertNotNull(image);
assertEquals(anImage, image);
}
Run Code Online (Sandbox Code Playgroud)
上下文xml如下所示:
<context:property-placeholder location="classpath:/config/config.properties" />
<bean id="imageScalingService" class="service.image.ImageScalingService">
<property name="maxWidth" value="${scaling.thumbnail.maxWidth}" />
<property name="maxHeight" value="${scaling.thumbnail.maxHeight}" />
</bean> …Run Code Online (Sandbox Code Playgroud) 所以我有一个在eclipse中运行的多模块Maven Web应用程序和带有wtp的tomcat.
但是,部署应用程序需要一些时间:如果更改了构建子模块,启动应用程序也需要几分钟.因此,我正在考虑使用JRebel来加速整个过程.但我不知道JRebel能否真正帮助我.大多数时候我在子模块中工作.因此,需要在我正在运行的Web应用程序中部署依赖项的更改.
我在http://en.wikipedia.org/wiki/JRebel上看到,JAR中的更新被忽略了.这仍然是真的吗?我看到有一些JRebel和Eclipse插件的maven插件.他们可以管理整个过程还是我在浪费时间?
所以我有以下情况:
@Entity
class Image {
@Id
@GeneratedValue
private Long id;
....
}
@Entity
class ImageData implements Serializable {
@Id
@OneToOne
private Image image;
....
}
Run Code Online (Sandbox Code Playgroud)
这一切都工作正常,但为什么 ImageData 需要可序列化?如果不是,我会收到异常,它需要可序列化:
org.hibernate.MappingException: composite-id class must implement Serializable:...
Run Code Online (Sandbox Code Playgroud)
我知道标识符需要可序列化,但为什么现在却相反了?
我正在使用JPA2和hibernate 3.6.1.和Derby数据库,我使用以下注释为blob:
@Column(length = Integer.MAX_VALUE)
@Lob
long[] bucket;
Run Code Online (Sandbox Code Playgroud)
Hibernate创建正确的blob列,但如果我尝试保存实体,则会出现以下异常:
java.lang.ClassCastException:[J无法强制转换为java.sql.Blob
为什么以及如何使这项工作?
如果我在没有@Lob的情况下注释它,我会得到一个"Varchar for bit data"列,最多只能包含32m.
我想通过JPA2获得我的前100个产品的平均价格.查询应该看起来像这样(我的sql有点生疏):
select avg(price) from (
select p.price from Product p order by p.price desc limit 100)
Run Code Online (Sandbox Code Playgroud)
但那根本不起作用.我也试过这个:
select avg(p.price) from Product p where p.id =
(select pj.id from Product pj order by pj.price desc limit 100)
Run Code Online (Sandbox Code Playgroud)
这是在限制关键字之前.
我读过JPQL中没有限制.
有关如何做到这一点的任何想法?标准也没关系.
jpa-2.0 ×3
blob ×2
hibernate ×2
java ×2
jpa ×2
deployment ×1
derby ×1
eclipse ×1
export ×1
image ×1
jpql ×1
jrebel ×1
maven ×1
mysql ×1
orm ×1
properties ×1
serializable ×1
spring ×1
sql ×1
unit-testing ×1