跪求compass中clob字段的解决方案!急!!!

编程界明世隐
Java领域优质创作者
博客专家认证
2008-11-20 10:41:35
我研究了一个compass的例子,是能跑的,可以正确的运行,现在有个这样的问题,要支持clob字段,所以我就在将clob字段配置了上去,但是报错:

2008-11-20 10:35:21 org.compass.core.config.CompassConfiguration configure
信息: Configuring from resource [/compass/compass.cfg.xml]
2008-11-20 10:35:21 org.compass.core.config.CompassConfiguration addResource
信息: Mapping resource [compass/alias.cmd.xml] in class loader
2008-11-20 10:35:21 org.compass.core.config.builder.DTDConfigurationBuilder processCompass
信息: Configured Compass [default]
2008-11-20 10:35:21 org.compass.core.config.CompassConfiguration addClass
信息: Mapping class [class compass.User]
Exception in thread "main" org.compass.core.mapping.MappingException: No converter defined for type [java.sql.Clob]
at org.compass.core.config.process.MappingProcessorUtils.resolveConverterByClass(MappingProcessorUtils.java:156)
at org.compass.core.config.process.MappingProcessorUtils.lookupConverter(MappingProcessorUtils.java:74)
at org.compass.core.config.process.ConverterLookupMappingProcessor$OsemConverterLookup.onClassPropertyMetaDataMapping(ConverterLookupMappingProcessor.java:136)
at org.compass.core.mapping.osem.OsemMappingIterator.iteratePropertyMapping(OsemMappingIterator.java:272)
at org.compass.core.mapping.osem.OsemMappingIterator.iterateMappings(OsemMappingIterator.java:186)
at org.compass.core.config.process.ConverterLookupMappingProcessor.lookupConverter(ConverterLookupMappingProcessor.java:86)
at org.compass.core.config.process.ConverterLookupMappingProcessor.process(ConverterLookupMappingProcessor.java:62)
at org.compass.core.config.CompassMappingProcessor.process(CompassMappingProcessor.java:57)
at org.compass.core.config.CompassConfiguration.buildCompass(CompassConfiguration.java:188)
at compass.Test.process(Test.java:31)
at compass.Test.main(Test.java:73)


下面是我加入clob字段后的配置:

alias.cmd.xml如下

<?xml version="1.0"?>
<!DOCTYPE compass-core-meta-data PUBLIC
"-//Compass/Compass Core Mapping DTD 1.0//EN"
"http://www.opensymphony.com/compass/dtd/compass-core-meta-data.dtd">
<compass-core-meta-data>
<meta-data-group id="mycompass" displayName="MyCompass Meta Data">
<description>MyCompass Meta Data</description>
<uri>http://compass/mycompass</uri>

<alias id="user" displayName="User">
<description>user alias</description>
<uri>http://compass/mycompass/User</uri>
<name>user</name>
</alias>
<meta-data id="id" displayName="Id">
<description>id alias</description>
<uri>http://compass/mycompass/Id</uri>
<name>id</name>
</meta-data>

<meta-data id="username" displayName="Username">
<description>username alias</description>
<uri>http://compass/mycompass/Username</uri>
<name>username</name>
</meta-data>

<meta-data id="content" displayName="Content">
<description>content alias</description>
<uri>http://compass/mycompass/Content</uri>
<name>content</name>
</meta-data>
</meta-data-group>
</compass-core-meta-data>

compass.cfg.xml如下:

<!DOCTYPE compass-core-configuration PUBLIC
"-//Compass/Compass Core Configuration DTD 1.0//EN"
"http://www.opensymphony.com/compass/dtd/compass-core-configuration.dtd">
<compass-core-configuration>
<compass name="default">
<setting name="compass.engine.connection">target/index</setting>
<meta-data
resource="compass/alias.cmd.xml" />
</compass>
</compass-core-configuration>

User.cpm.xml如下

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE compass-core-mapping PUBLIC
"-//Compass/Compass Core Mapping DTD 1.0//EN"
"http://www.opensymphony.com/compass/dtd/compass-core-mapping.dtd">
<compass-core-mapping package="compass">
<class name="User" alias="${mycompass.user}">
<id name="id" />
<property name="username">
<meta-data>${mycompass.username}</meta-data>
</property>
<property name="content">
<meta-data>${mycompass.content}</meta-data>
</property>
</class>
</compass-core-mapping>

User类:


public class User implements java.io.Serializable {

private int id;
private String username;
private Clob content;

public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Clob getContent() {
return content;
}
public void setContent(Clob content) {
this.content = content;
}

}

测试类:

public class Test {

private static Compass compass;

/**
* @Description 方法实现功能描述
* @param args
* void
* @throws 抛出异常说明
*/
public void process() {
CompassConfiguration config = new CompassConfiguration();
config.configure("/compass/compass.cfg.xml");
config.addClass(User.class);

compass = config.buildCompass();
System.out.println("compass=" + compass);
}

private User addUser() {
User user = new User();
user.setId(1);
user.setUsername("ding");
return user;
}

private void createIndex(User user) { // 建立索引,与Hibernate很相似
CompassSession session = compass.openSession();
CompassTransaction tx = session.beginTransaction();
session.save(user);
tx.commit();
session.close();
}

private void search(String keyword) { // 根据关键字keyword检索
CompassSession session = compass.openSession();
CompassTransaction tx = session.beginTransaction();
CompassHits hits = session.find(keyword);

System.out.println("检索关键字 " + keyword + " 的检索结果如下:");
System.out.println("********************************************");
for (int i = 0; i < hits.getLength(); i++) {
User user = (User) hits.data(i);
System.out.println("ID为: " + user.getId());
System.out.println("Username为: " + user.getUsername());
System.out.println("********************************************");
}
System.out.println("共检索出结果 " + hits.length() + " 个。");
hits.close();
tx.commit();
session.close();
compass.close();
}


public static void main(String[] args) {
Test myCompass = new Test();
myCompass.process();
compass.getSearchEngineIndexManager().deleteIndex();
compass.getSearchEngineIndexManager().createIndex();

myCompass.createIndex(myCompass.addUser());
myCompass.search("in~");
}

}

若是把clob相关的去掉则是对的,这里加入clob后就不行了,是否compass不支持呢?
望大家帮忙,谢过先。


...全文
471 5 打赏 收藏 举报
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
compass在现在不知道用的是不是很多
  • 打赏
  • 举报
回复
假设col2是CLOB:
写操作:

String sql = "insert into tb_commendtemp (col1,col2) values('111',?)";
string s = "长文本";
StringBufferInputStream sbin = new StringBufferInputStream(s);
PreparedStatement ps = query.getPreStmt(sql);
ps.setAsciiStream(1,sbin,s.length());
int i = ps.executeUpdate();
ps.close();
sbin.close();
if(i>0) ok;
如果是二进制文件就用FileInputStream写进去

读的时候只要
rs.getAsciiStream();
rs.getUnicodeStream();
rs.getBinaryStream();
看它们的名字就知道是得到什么类型的的数据流了.

如果存放的是二进制文件,比如图形,执行文件,压缩文件最好还是blob保险.
写和读也要用二进制流,
DataInputStrean和DatOutputStream.有时用UNICODE的字符流也能行,但
不保险.如果是文本,用Clob和LONG都行.读和写用
BuffreedReader和PrintWriter更方便.



本篇文章来源于 黑客基地-全球最大的中文黑客站 原文链接:http://www.hackbase.com/lib/2008-07-17/23407.html
  • 打赏
  • 举报
回复
问题是数据库就有clob字段啊,我也不想拿clob来做测试啊,。。。。
用String简单方便
  • 打赏
  • 举报
回复
林g 2008-11-20
up
  • 打赏
  • 举报
回复
老紫竹 2008-11-20
Exception in thread "main" org.compass.core.mapping.MappingException: No converter defined for type [java.sql.Clob]
我看你用String类型算了
  • 打赏
  • 举报
回复
相关推荐
发帖
Web 开发

8.0w+

社区成员

Java Web 开发
社区管理员
  • Web 开发社区
加入社区
帖子事件
创建了帖子
2008-11-20 10:41
社区公告
暂无公告