- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
员工 Bean 类:
public class Employee2 {
private String id;
private String name;
private String designation;
private double salary;
private double totalExperience;
// private Address2 address2;
private Collection<Technology2> technologies2;
private String content_type = "employee2";
public Employee2() {
super();
}
public Employee2(String id, String name, String designation, double salary, double totalExperience,
Collection<Technology2> technologies2) {
super();
this.id = id;
this.name = name;
this.designation = designation;
this.salary = salary;
this.totalExperience = totalExperience;
// this.address2 = address2;
this.technologies2 = technologies2;
}
/**
* @return the id
*/
public String getId() {
return id;
}
/**
* @param id the id to set
*/
@Field (value = "id")
public void setId(String id) {
this.id = id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
@Field (value = "name")
public void setName(String name) {
this.name = name;
}
/**
* @return the designation
*/
public String getDesignation() {
return designation;
}
/**
* @param designation the designation to set
*/
@Field (value = "designation_s")
public void setDesignation(String designation) {
this.designation = designation;
}
/**
* @return the salary
*/
public double getSalary() {
return salary;
}
/**
* @param salary the salary to set
*/
@Field (value = "salary_d")
public void setSalary(double salary) {
this.salary = salary;
}
/**
* @return the totalExperience
*/
public double getTotalExperience() {
return totalExperience;
}
/**
* @param totalExperience the totalExperience to set
*/
@Field (value = "totalExperience_d")
public void setTotalExperience(double totalExperience) {
this.totalExperience = totalExperience;
}
// /**
// * @return the address2
// */
// public Address2 getAddress() {
// return address2;
// }
//
// /**
// * @param address2 the address2 to set
// */
// @Field (child = true)
// public void setAddress(Address2 address2) {
// this.address2 = address2;
// }
/**
* @return the technologies2
*/
public Collection<Technology2> getTechnologies2() {
return technologies2;
}
/**
* @param technologies2 the technologies2 to set
*/
@Field (child = true)
public void setTechnologies2(Collection<Technology2> technologies2) {
this.technologies2 = technologies2;
}
/**
* @return the content_type
*/
public String getContent_type() {
return content_type;
}
/**
* @param content_type the content_type to set
*/
@Field(value="content_type_t")
public void setContent_type(String content_type) {
this.content_type = content_type;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Employee2 [id=" + id + ", name=" + name + ", designation=" + designation + ", salary=" + salary +
", totalExperience=" + totalExperience + ", technologies2=" + this.getTechnologies(technologies2) +
", content_type=" + content_type + "]";
}
private String getTechnologies(Collection<Technology2> technologies2) {
String strTechnologies = "[";
for(Technology2 technology: technologies2) {
strTechnologies = strTechnologies+technology.toString();
}
return strTechnologies+"]";
}
}
public class Technology2 {
private String id;
private String name;
private int experience;
private boolean certified;
private String content_type = "technology2";
public Technology2() {
super();
}
public Technology2(String id, String name, int experience, boolean certified) {
super();
this.id = id;
this.name = name;
this.experience = experience;
this.certified = certified;
}
/**
* @return the id
*/
public String getId() {
return id;
}
/**
* @param id the id to set
*/
@Field(value="id")
public void setId(String id) {
this.id = id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
@Field(value="name")
public void setName(String name) {
this.name = name;
}
/**
* @return the experience
*/
public int getExperience() {
return experience;
}
/**
* @param experience the experience to set
*/
@Field(value="experience_i")
public void setExperience(int experience) {
this.experience = experience;
}
/**
* @return the certified
*/
public boolean getCertified() {
return certified;
}
/**
* @param certified the certified to set
*/
@Field(value="certified_b")
public void setCertified(boolean certified) {
this.certified = certified;
}
/**
* @return the content_type
*/
public String getContent_type() {
return content_type;
}
/**
* @param content_type the content_type to set
*/
@Field(value="content_type_t")
public void setContent_type(String content_type) {
this.content_type = content_type;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Technology2 [id=" + id + ", name=" + name + ", experience=" + experience + ", certified=" + certified +
", content_type=" + content_type + "]";
}
UpdateResponse response = solrClient.addBean(bean);
public <T> boolean insert (T bean) {
try {
UpdateResponse response = solrClient.addBean(bean);
System.out.println("insert bean ElapsedTime: " + response.getElapsedTime());
solrClient.commit();
return true;
} catch (IOException | SolrServerException e) {
e.printStackTrace();
}
return false;
}
Employee2 [id=EE130S, name=Vulrp, designation=NjLtK, salary=127334.59626719051, totalExperience=49.989444163266164, technologies2=[Technology2 [id=0TE130S, name=uyIOFlh, experience=21, certified=true, content_type=technology2]Technology2 [id=1TE130S, name=FmZJjak, experience=43, certified=false, content_type=technology2]Technology2 [id=2TE130S, name=ddJbOXg, experience=11, certified=false, content_type=technology2]Technology2 [id=3TE130S, name=rIxumUe, experience=5, certified=true, content_type=technology2]], content_type=employee2]
java.lang.NullPointerException
at org.apache.solr.client.solrj.beans.DocumentObjectBinder$DocField.storeType(DocumentObjectBinder.java:243)
at org.apache.solr.client.solrj.beans.DocumentObjectBinder$DocField.<init>(DocumentObjectBinder.java:183)
at org.apache.solr.client.solrj.beans.DocumentObjectBinder.collectInfo(DocumentObjectBinder.java:144)
at org.apache.solr.client.solrj.beans.DocumentObjectBinder.getDocFields(DocumentObjectBinder.java:123)
at org.apache.solr.client.solrj.beans.DocumentObjectBinder.toSolrInputDocument(DocumentObjectBinder.java:76)
at org.apache.solr.client.solrj.SolrClient.addBean(SolrClient.java:277)
at org.apache.solr.client.solrj.SolrClient.addBean(SolrClient.java:259)
at com.opteamix.buildpal.poc.SampleSolrDAO.insert(SampleSolrDAO.java:62)
at com.opteamix.buildpal.poc.SampleSolrDAOTest.testEmployees2Insert(SampleSolrDAOTest.java:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
最佳答案
插入与 bean 列表相关联的 bean 对象现在按预期工作。
终于在查看了solrj6.0.0源码后,找到了解决的方法。实际上 solrj6.0.0 中存在一个错误。那是:
如果我们在 Employee2 bean 的 set 方法中给出 @Field 注释,如下所示:
/**
* @param technologies2 the technologies2 to set
*/
@Field (child = true)
public void setTechnologies2(Collection<Technology2> technologies2) {
this.technologies2 = technologies2;
}
Nested DocField class of DocumentObjectBinder has below implemention:
public DocField(AccessibleObject member) {
if (member instanceof java.lang.reflect.Field) {
field = (java.lang.reflect.Field) member;
} else {
setter = (Method) member;
}
annotation = member.getAnnotation(Field.class);
storeName(annotation);
storeType();
// Look for a matching getter
if (setter != null) {
String gname = setter.getName();
if (gname.startsWith("set")) {
gname = "get" + gname.substring(3);
try {
getter = setter.getDeclaringClass().getMethod(gname, (Class[]) null);
} catch (Exception ex) {
// no getter -- don't worry about it...
if (type == Boolean.class) {
gname = "is" + setter.getName().substring(3);
try {
getter = setter.getDeclaringClass().getMethod(gname, (Class[]) null);
} catch(Exception ex2) {
// no getter -- don't worry about it...
}
}
}
}
}
}
private void storeType() {
if (field != null) {
type = field.getType();
} else {
Class[] params = setter.getParameterTypes();
if (params.length != 1) {
throw new BindingException("Invalid setter method. Must have one and only one parameter");
}
type = params[0];
}
if (type == Collection.class || type == List.class || type == ArrayList.class) {
isList = true;
if (annotation.child()) {
populateChild(field.getGenericType());
} else {
type = Object.class;
}
} else if (type == byte[].class) {
//no op
} else if (type.isArray()) {
isArray = true;
if (annotation.child()) {
populateChild(type.getComponentType());
} else {
type = type.getComponentType();
}
} else if (type == Map.class || type == HashMap.class) { //corresponding to the support for dynamicFields
if (annotation.child()) throw new BindingException("Map should is not a valid type for a child document");
isContainedInMap = true;
//assigned a default type
type = Object.class;
if (field != null) {
if (field.getGenericType() instanceof ParameterizedType) {
//check what are the generic values
ParameterizedType parameterizedType = (ParameterizedType) field.getGenericType();
Type[] types = parameterizedType.getActualTypeArguments();
if (types != null && types.length == 2 && types[0] == String.class) {
//the key should always be String
//Raw and primitive types
if (types[1] instanceof Class) {
//the value could be multivalued then it is a List, Collection, ArrayList
if (types[1] == Collection.class || types[1] == List.class || types[1] == ArrayList.class) {
type = Object.class;
isList = true;
} else {
//else assume it is a primitive and put in the source type itself
type = (Class) types[1];
}
} else if (types[1] instanceof ParameterizedType) { //Of all the Parameterized types, only List is supported
Type rawType = ((ParameterizedType) types[1]).getRawType();
if (rawType == Collection.class || rawType == List.class || rawType == ArrayList.class) {
type = Object.class;
isList = true;
}
} else if (types[1] instanceof GenericArrayType) { //Array types
type = (Class) ((GenericArrayType) types[1]).getGenericComponentType();
isArray = true;
} else { //Throw an Exception if types are not known
throw new BindingException("Allowed type for values of mapping a dynamicField are : " +
"Object, Object[] and List");
}
}
}
}
} else {
if (annotation.child()) {
populateChild(type);
}
}
}
@Field (child = true)
private Collection<Technology2> technologies2;
Employee2 [id=E3, name=KzWhg, designation=aTDiu, salary=190374.70126209356, totalExperience=2.0293696897450584, technologies2=[Technology2 [id=0T3, name=nxTdufv, experience=46, certified=false, content_type=technology2]Technology2 [id=1T3, name=waSMXpf, experience=26, certified=false, content_type=technology2]Technology2 [id=2T3, name=jqNbZZr, experience=30, certified=true, content_type=technology2]Technology2 [id=3T3, name=VnidjyI, experience=21, certified=true, content_type=technology2]Technology2 [id=4T3, name=ulGnHFm, experience=33, certified=false, content_type=technology2]Technology2 [id=5T3, name=cpUfgrY, experience=21, certified=false, content_type=technology2]], content_type=employee2] Employee2 [id=E4, name=xeKOY, designation=WfPSm, salary=169700.53869292728, totalExperience=22.047282596410284, technologies2=[Technology2 [id=0T4, name=rleygcW, experience=30, certified=true, content_type=technology2]Technology2 [id=1T4, name=yxjHrxV, experience=27, certified=false, content_type=technology2]Technology2 [id=2T4, name=czjHAEE, experience=31, certified=false, content_type=technology2]Technology2 [id=3T4, name=RDhoIJw, experience=22, certified=false, content_type=technology2]Technology2 [id=4T4, name=UkbldDN, experience=19, certified=false, content_type=technology2]], content_type=employee2] Employee2 [id=E5, name=tIWuY, designation=WikuL, salary=41462.47225086359, totalExperience=13.407976384902403, technologies2=[Technology2 [id=0T5, name=CDCMunq, experience=6, certified=false, content_type=technology2]Technology2 [id=1T5, name=NmkADyB, experience=31, certified=false, content_type=technology2]Technology2 [id=2T5, name=IhXnLfc, experience=9, certified=true, content_type=technology2]], content_type=employee2] Employee2 [id=E6, name=YluDp, designation=EtFqG, salary=159724.66206009954, totalExperience=26.26819742766281, technologies2=[Technology2 [id=0T6, name=mFvKDIK, experience=33, certified=false, content_type=technology2]Technology2 [id=1T6, name=arTNoHj, experience=44, certified=true, content_type=technology2]Technology2 [id=2T6, name=KYMseTW, experience=34, certified=false, content_type=technology2]Technology2 [id=3T6, name=ZTphSVn, experience=13, certified=true, content_type=technology2]], content_type=employee2] Employee2 [id=E7, name=qMkKG, designation=SQHCo, salary=111861.53447042785, totalExperience=13.29234679211927, technologies2=[Technology2 [id=0T7, name=PTKxjFl, experience=23, certified=false, content_type=technology2]Technology2 [id=1T7, name=gJfxbto, experience=17, certified=true, content_type=technology2]Technology2 [id=2T7, name=eekPYPN, experience=40, certified=true, content_type=technology2]Technology2 [id=3T7, name=aRdsEag, experience=40, certified=true, content_type=technology2]Technology2 [id=4T7, name=loDFVyM, experience=40, certified=true, content_type=technology2]Technology2 [id=5T7, name=xPXNaDV, experience=0, certified=false, content_type=technology2]], content_type=employee2] Employee2 [id=E8, name=WyNsf, designation=TtanH, salary=107942.13641940584, totalExperience=47.036469485140984, technologies2=[Technology2 [id=0T8, name=kakGXqh, experience=14, certified=true, content_type=technology2]Technology2 [id=1T8, name=ugwgdHy, experience=9, certified=true, content_type=technology2]Technology2 [id=2T8, name=rNzwcdQ, experience=31, certified=false, content_type=technology2]Technology2 [id=3T8, name=ZBXUhuB, experience=6, certified=true, content_type=technology2]], content_type=employee2] Employee2 [id=E9, name=EzuLC, designation=IXYGj, salary=133064.4485190016, totalExperience=16.075378097234232, technologies2=[Technology2 [id=0T9, name=GmvOUWp, experience=5, certified=true, content_type=technology2]Technology2 [id=1T9, name=ZWyvRxk, experience=24, certified=false, content_type=technology2]Technology2 [id=2T9, name=uWkTrfB, experience=5, certified=false, content_type=technology2]Technology2 [id=3T9, name=NFknqJj, experience=29, certified=true, content_type=technology2]], content_type=employee2] Employee2 [id=E10, name=quFKB, designation=eUoBJ, salary=198332.3270496455, totalExperience=14.035578311712438, technologies2=[Technology2 [id=0T10, name=MOXduwi, experience=49, certified=false, content_type=technology2]Technology2 [id=1T10, name=LpXGRvn, experience=28, certified=false, content_type=technology2]Technology2 [id=2T10, name=QeAOjIp, experience=3, certified=true, content_type=technology2]Technology2 [id=3T10, name=aVxGhOV, experience=34, certified=true, content_type=technology2]Technology2 [id=4T10, name=fbSaBUm, experience=42, certified=true, content_type=technology2]], content_type=employee2]
关于indexing - SOLRJ-6.0.0 : Insertion of a bean object which associate list of bean object is giving null pointer exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37241489/
最近开始学习oracle和sql。 在学习的过程中,我遇到了几个问题,我的 friend 在接受采访时被问到这些问题。 SELECT * FROM Employees WHERE NULL IS N
这个问题在这里已经有了答案: Can we subtract NULL pointers? (4 个回答) 关闭 2 个月前。 是否定义了NULL - NULL? (char *)NULL - (ch
是否有推荐的方法(根据 .net Framework 指南)检查 null,例如: if (value == null) {//code1} else {//code2} 或 if (value !=
我正在尝试将值插入数据库,但出现这样的错误任何人都可以告诉我为什么该值为空,如下所示: An exception occurred while executing 'INSERT INTO perso
这个问题在这里已经有了答案: String concatenation with a null seems to nullify the entire string - is that desire
您好,我正在 Android 联系人搜索模块中工作。我正在查询下方运行。 cur = context.getContentResolver().query(ContactsContract.Data.
下面的 SQL 表定义说明了从我的 MYSQL 数据库创建表的语句之一,该数据库是由我公司的前开发人员开发的。 DROP TABLE IF EXISTS `classifieds`.`category
我主要有应用程序开发背景。在编程语言中 variable == null或 variable != null有效。 当涉及到 SQL 时,以下查询不会给出任何语法错误,但也不会返回正确的结果。 sel
我在尝试检查某些元素是否为 NULL 时遇到段错误或不。任何人都可以帮忙吗? void addEdge(int i, int j) { if (i >= 0 && j > 0)
在 SQL 服务器中考虑到以下事实:Col1 和 Col2 包含数值和 NULL 值 SELECT COALESCE(Col1,Col2) 返回一个错误:“COALESCE 的至少一个参数必须是一个不
在 SQL 服务器中考虑到以下事实:Col1 和 Col2 包含数值和 NULL 值 SELECT COALESCE(Col1,Col2) 返回一个错误:“COALESCE 的至少一个参数必须是一个不
下面查询的关系代数表达式是什么?我找不到“Is Null”的表达式。 SELECT reader.name FROM reader LEFT JOIN book_borrow ON reader.ca
我正在尝试使用三元运算符来检查值是否为 null 并返回一个表达式或另一个。将此合并到 LINQ 表达式时,我遇到的是 LINQ 表达式的 Transact-SQL 转换试图执行“column = n
我在给定的代码中看到了以下行: select(0, (fd_set *) NULL, (fd_set *) NULL, (fd_set *) NULL, &timeout); http://linux
var re = /null/g; re.test('null null'); //> true re.test('null null'); //> true re.test('null null')
这个问题在这里已经有了答案: 关闭 13 年前。 我今天避开了一场关于数据库中空值的激烈辩论。 我的观点是 null 是未指定值的极好指示符。团队中有意见的其他每个人都认为零和空字符串是可行的方法。
由于此错误,我无法在模拟器中运行我的应用: Error:null value in entry: streamOutputFolder=null 或 gradle - Error:null value
我正在尝试在 Android 应用程序中创建电影数据库,但它返回错误。知道这意味着什么吗? public Cursor returnData() { return db.query(TABLE
我一直在检查浏览器中的日期函数以及运行时间 new Date (null, null, null); 在开发工具控制台中,它给出了有效的日期 Chrome v 61 回归 Sun Dec 31 189
为什么 NA==NULL 会导致 logical (0) 而不是 FALSE? 为什么 NULL==NULL 会导致 logical(0) 而不是 TRUE? 最佳答案 NULL 是一个“零长度”对象
我是一名优秀的程序员,十分优秀!