Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Issues with hibernate jpa 2.1 compatibility
PostPosted: Mon Nov 23, 2015 1:56 am 
Newbie

Joined: Fri Nov 06, 2015 5:06 am
Posts: 12
Hi all,

I have migrated to hibernate search 5.5.0 from hibernate search 4.3.0, with hibernate jpa migrating from 2.0 to 2.1.
since my code was running on the older annotations so after migrating, I am getting the following run time exception:::

Error creating bean with name 'myBean' defined in class path resource [spring-config.xml]: Invocation of init method failed; nested exception is org.hibernate.search.exception.SearchException: HSEARCH000247: An indexed field defined on 'MyClass:transKey' tries to override the id field settings. The document id field settings cannot be modified. Use a different field name.

after analysis it was found that the jpa 2.0 code was not compatible with the new version of jpa i.e 2.1

@Id
@EmbeddedId
@FieldBridge(impl=MyClassl_keyBridge.class)
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.YES)
private MyClass transKey;

@Id is not suppose to come with @EmbeddedId. So i removed the @Id annotation so I am now getting the foll exception::

Caused by: org.hibernate.search.exception.SearchException: HSEARCH000177: Unable to find a valid document id for entity 'MyClass'
at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.<init>(DocumentBuilderIndexedEntity.java:156)
at org.hibernate.search.spi.SearchIntegratorBuilder.initDocumentBuilders(SearchIntegratorBuilder.java:381)
at org.hibernate.search.spi.SearchIntegratorBuilder.buildNewSearchFactory(SearchIntegratorBuilder.java:199)
at org.hibernate.search.spi.SearchIntegratorBuilder.buildSearchIntegrator(SearchIntegratorBuilder.java:117)
at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:75)
at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:35)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:541)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:416)
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:401)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java


Can anyone help me with it pls very urgent?


Top
 Profile  
 
 Post subject: Re: Issues with hibernate jpa 2.1 compatibility
PostPosted: Mon Nov 23, 2015 4:27 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 386
Hi,

It should work if you add the org.hibernate.search.annotations.DocumentId annotation.

Indeed it works without that if javax.persistence.Id is given, whereas it's needed with javax.persistence.EmbeddedId. I'll check whether we can make it superfluous in that case, too.

Hth,

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: Issues with hibernate jpa 2.1 compatibility
PostPosted: Mon Nov 23, 2015 8:29 am 
Newbie

Joined: Fri Nov 06, 2015 5:06 am
Posts: 12
Thanks for your reply!


https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/EmbeddedId.html

If you go through this link, it is clearly mentioned that @Id cannot be used with @EmbeddedId. So cannot go with this approach. moreover, I have tried using @DocumentId as well with it, but then I get foll exception:

Error creating bean with name 'myBean' defined in class path resource [spring-config.xml]: Invocation of init method failed; nested exception is org.hibernate.search.exception.SearchException: HSEARCH000247: An indexed field defined on 'MyClass:transKey' tries to override the id field settings. The document id field settings cannot be modified. Use a different field name.

This is the structure of my classes

@Entity
@Indexed
@Analyzer(impl = org.apache.lucene.analysis.standard.StandardAnalyzer.class)
class A{

@OneToMany
@JoinColumn(name = "trans_id")
@IndexedEmbedded
private Set<B> b;

}

@Entity
@Indexed
//@Table(name = "AUDITDB_SDP_TRANS_DTL")//To work against R11 code - need to remove when deploying to R12
@Analyzer(impl = org.apache.lucene.analysis.standard.StandardAnalyzer.class)
class B{
@Id
@EmbeddedId
@FieldBridge(impl=C1_keyBridge.class)
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.YES)
private C transKey;

}

@Embeddable
@Indexed
@Analyzer(impl = org.apache.lucene.analysis.standard.StandardAnalyzer.class)
class C{
private String trans_id;
private Timestamp msg_date;
}

Please help me with it....


Top
 Profile  
 
 Post subject: Re: Issues with hibernate jpa 2.1 compatibility
PostPosted: Mon Nov 23, 2015 9:02 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 386
Hi,

The exception basically says it all:

Quote:
An indexed field defined on 'MyClass:transKey' tries to override the id field settings.


Just remove the @Field annotation, Hibernate Search itself will create the id field implicitly. If you need another Lucene field for the id property configured differently for some reason, you need to give that field another name via @Field#name().

Hth,

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: Issues with hibernate jpa 2.1 compatibility
PostPosted: Tue Nov 24, 2015 1:11 am 
Newbie

Joined: Fri Nov 06, 2015 5:06 am
Posts: 12
Removing the @Field annotation will not solve my purpose. As you can see from the annotations of the 3 classes i mentioned, the @Field annotation is used for storing it as a lucene index:

@Id
@EmbeddedId
@FieldBridge(impl=C1_keyBridge.class)
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.YES)
private C transKey;

So the whole purpose of indexing it will be finished if i will remove the @field annotation from the top of the "private C transKey;"

And also, like I mentioned, that in jpa 2.1 @Id and @EmbeddedId cannot be used together as EmbeddedId itself works as a key ,as per jpa 2.1 specification..

So in short, there a re 2 point on which I wanted a clarity..

1) removing the @Field annotation from that particular field will vanish my purpose of indexing. So how to handle that then.

2) as per jpa 2.1 specification , ideally @Id and @embeddedId should not be used together, so should something be done over there as well?

Thanks in advance...


Top
 Profile  
 
 Post subject: Re: Issues with hibernate jpa 2.1 compatibility
PostPosted: Tue Nov 24, 2015 3:42 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 386
Quote:
So the whole purpose of indexing it will be finished if i will remove the @field annotation from the top of the "private C transKey;"

Hibernate Search will implicitly create a field for the id property (as marked via @Id or @Documentid), no need to explicitly configure it via @Field. Only if you need *another* field with a different configuration, you should create it via @Field.

Quote:
And also, like I mentioned, that in jpa 2.1 @Id and @EmbeddedId cannot be used together

Yes, I understand that ;) Hence I said you should add Hibernate Search's @DocumentId annotation, not JPA's @Id. So that's how it should look like:

Code:
@DocumentId
@EmbeddedId
@FieldBridge(impl=C1_keyBridge.class)
private C transKey;


Cheers,

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: Issues with hibernate jpa 2.1 compatibility
PostPosted: Tue Nov 24, 2015 4:26 am 
Newbie

Joined: Fri Nov 06, 2015 5:06 am
Posts: 12
Thank you sooooo much for this suggestion.. My exception is gone!!!!!! :) :)


But please can you provide me a reference where I can read about this :

Quote:
Hibernate Search will implicitly create a field for the id property (as marked via @Id or @Documentid), no need to explicitly configure it via @Field.


Is this change specific to jpa 2.1 or so?

And also, I dint get this:

Quote:
Only if you need *another* field with a different configuration, you should create it via @Field.


Can you please explain with an example?

Thnka,
Sonal


Top
 Profile  
 
 Post subject: Re: Issues with hibernate jpa 2.1 compatibility
PostPosted: Tue Nov 24, 2015 5:59 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 386
Glad to hear I could help :)

Quote:
But please can you provide me a reference where I can read about this


E.g. check out section 4.1.1.5. ("@Id") in the reference guide: http://docs.jboss.org/hibernate/search/5.5/reference/en-US/html_single/. The example shows how four fields are created while only three @Field annotations are given.

Quote:
Can you please explain with an example?


Take a look at the example in section 4.1.2 ("Mapping properties multiple times", http://docs.jboss.org/hibernate/search/5.5/reference/en-US/html_single/#fields-annotation). A single property can be mapped to multiple fields in the index, e.g. if you need an analyzed field for searching and an un-analyzed field for sorting purposes. Normally you'd use several @Field annotations to define the fields. For the id property you only need an @Field annotation for each field to be created *in addition* to the id field created implicitly by Hibernate Search.

In particular you are not allowed to re-configure the implicitly created field, that was the error you saw before "...ries to override the id field settings...").

Cheers,

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: Issues with hibernate jpa 2.1 compatibility
PostPosted: Wed Nov 25, 2015 3:37 am 
Newbie

Joined: Fri Nov 06, 2015 5:06 am
Posts: 12
Actually this is not exactly the scenario here...

This is the whole structure:

@Entity
@Indexed
@Analyzer(impl = org.apache.lucene.analysis.standard.StandardAnalyzer.class)
public class A {
@Id
@DocumentId
private String trans_id;

@OneToMany
@JoinColumn(name = "trans_id")
@IndexedEmbedded
private Set<B> B_obj;
}

@Entity
@Indexed
@Analyzer(impl = org.apache.lucene.analysis.standard.StandardAnalyzer.class)
public class B {

@Id
@EmbeddedId
@FieldBridge(impl=com.att.ssam.txtsearch.utils.Ssam_trans_dtl_keyBridge.class)
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.YES)
private C transKey;

public C getTransKey() {
return transKey;
}
}


@Embeddable
@Indexed
@Analyzer(impl = org.apache.lucene.analysis.standard.StandardAnalyzer.class)
public class C implements Serializable {

private static final long serialVersionUID = 1L;
private String trans_id;
private Timestamp msg_date;

C() {}
}

as you can see from above, my C class is being used as a composite key in class B, and in class B, it is getting stored as an index through :
Quote:
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.YES)
private C transKey;


So there is no such multiple mapping scenario here..

Which is why I asked this question:

Quote:
Hibernate Search will implicitly create a field for the id property (as marked via @Id or @Documentid), no need to explicitly configure it via @Field.
Is this change specific to jpa 2.1 or so?


Please can you clarify my doubt... Now I am getting totally confused...


Also to mention:

Quote:
Hibernate Search will implicitly create a field for the id property (as marked via @Id or @Documentid), no need to explicitly configure it via @Field.


If it will implicitly create an index or we can say field for the prop, then will it work with the default settings of @field annotation? i.e index=Index.YES, analyze=Analyze.YES and store=Store.NO are the default values

but i want :
index=Index.YES, analyze=Analyze.YES, store=Store.YES

these settings, so will it be handling it implicitly?


Top
 Profile  
 
 Post subject: Re: Issues with hibernate jpa 2.1 compatibility
PostPosted: Thu Nov 26, 2015 1:53 am 
Newbie

Joined: Fri Nov 06, 2015 5:06 am
Posts: 12
Hi,

Can anyone please provide me an update on this?

-------------------------------------------------------

Actually this is not exactly the scenario here...

This is the whole structure:

@Entity
@Indexed
@Analyzer(impl = org.apache.lucene.analysis.standard.StandardAnalyzer.class)
public class A {
@Id
@DocumentId
private String trans_id;

@OneToMany
@JoinColumn(name = "trans_id")
@IndexedEmbedded
private Set<B> B_obj;
}

@Entity
@Indexed
@Analyzer(impl = org.apache.lucene.analysis.standard.StandardAnalyzer.class)
public class B {

@Id
@EmbeddedId
@FieldBridge(impl=com.att.ssam.txtsearch.utils.Ssam_trans_dtl_keyBridge.class)
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.YES)
private C transKey;

public C getTransKey() {
return transKey;
}
}


@Embeddable
@Indexed
@Analyzer(impl = org.apache.lucene.analysis.standard.StandardAnalyzer.class)
public class C implements Serializable {

private static final long serialVersionUID = 1L;
private String trans_id;
private Timestamp msg_date;

C() {}
}

as you can see from above, my C class is being used as a composite key in class B, and in class B, it is getting stored as an index through :
Quote:
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.YES)
private C transKey;


So there is no such multiple mapping scenario here..

Which is why I asked this question:

Quote:
Hibernate Search will implicitly create a field for the id property (as marked via @Id or @Documentid), no need to explicitly configure it via @Field.
Is this change specific to jpa 2.1 or so?


Please can you clarify my doubt... Now I am getting totally confused...


Also to mention:

Quote:
Hibernate Search will implicitly create a field for the id property (as marked via @Id or @Documentid), no need to explicitly configure it via @Field.


If it will implicitly create an index or we can say field for the prop, then will it work with the default settings of @field annotation? i.e index=Index.YES, analyze=Analyze.YES and store=Store.NO are the default values

but i want :
index=Index.YES, analyze=Analyze.YES, store=Store.YES

these settings, so will it be handling it implicitly?


Top
 Profile  
 
 Post subject: Re: Issues with hibernate jpa 2.1 compatibility
PostPosted: Thu Nov 26, 2015 7:09 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 386
The fact that Hibernate Search implicitly creates a field for the id property is not related to JPA 2.1.

The default id field is configured as not analyzed but it is stored. Note that it is your field bridge which you configured that is in charge of actually writing this field. If you need another field (e.g. analyzed), you may either just add this field from within your field bridge, or you configure that field through an explicit @Field annotation. In that case, Hibernate Search will invoke your bridge twice, once for the implicit id property field and once for that other explicitly given field.

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: Issues with hibernate jpa 2.1 compatibility
PostPosted: Mon Dec 07, 2015 12:47 am 
Newbie

Joined: Fri Nov 06, 2015 5:06 am
Posts: 12
Thanks for all the help! :)


Top
 Profile  
 
 Post subject: Re: Issues with hibernate jpa 2.1 compatibility
PostPosted: Mon Feb 01, 2016 3:48 am 
Newbie

Joined: Fri Nov 06, 2015 5:06 am
Posts: 12
Hi team,

I am using hibernate Full text search functionality in my application, Following are the specifications:

-Hibernate search 5.5.0
-Lucene 5.3
-Hibernate core 5.0.1
-hibernate-jpa-2.1-api-1.0.0.Final.jar
-Hibernate entity manager 5.0.1
-spring 4.2.1
-ejb 2.1

The application is deployed on IBM WAS servers and following is the exception I am getting during deployment:

29/16 16:55:47:642 CST] FFDC Exception:java.lang.ClassNotFoundException SourceId:com.ibm.ws.jpa.management.JPAComponentImpl.discoverServerScopePersistenceProviders ProbeId:445 Reporter:com.ibm.ws.jpa.management.JPAComponentImpl@bec837b3
java.lang.ClassNotFoundException: #
at java.lang.Class.forNameImpl(Native Method)
at java.lang.Class.forName(Class.java:181)
at com.ibm.ws.jpa.management.JPAComponentImpl.discoverPersistenceProviders(JPAComponentImpl.java:448)
at com.ibm.ws.jpa.management.AbstractJPAComponent.getEffectiveDefaultJPAProviderClassName(AbstractJPAComponent.java:243)
at com.ibm.ws.jpa.management.AbstractJPAComponent.initialize(AbstractJPAComponent.java:139)
at com.ibm.ws.jpa.management.JPAComponentImpl.initialize(JPAComponentImpl.java:175)
at com.ibm.ws.runtime.component.ContainerHelper.initWsComponent(ContainerHelper.java:1192)
at com.ibm.ws.runtime.component.ContainerHelper.initializeComponent(ContainerHelper.java:1099)
at com.ibm.ws.runtime.component.ContainerHelper.initializeComponents(ContainerHelper.java:950)
at com.ibm.ws.runtime.component.ContainerImpl.initializeComponents(ContainerImpl.java:776)
at com.ibm.ws.runtime.component.ContainerImpl.initializeComponents(ContainerImpl.java:750)
at com.ibm.ws.runtime.component.ApplicationServerImpl.initialize(ApplicationServerImpl.java:192)
at com.ibm.ws.runtime.component.ContainerHelper.initWsComponent(ContainerHelper.java:1192)
at com.ibm.ws.runtime.component.ContainerHelper.initializeComponent(ContainerHelper.java:1099)
at com.ibm.ws.runtime.component.ContainerHelper.initializeComponents(ContainerHelper.java:928)
at com.ibm.ws.runtime.component.ContainerImpl.initializeComponents(ContainerImpl.java:776)
at com.ibm.ws.runtime.component.ContainerImpl.initializeComponents(ContainerImpl.java:750)
at com.ibm.ws.runtime.component.ServerImpl.initialize(ServerImpl.java:353)
at com.ibm.ws.runtime.WsServerImpl.bootServerContainer(WsServerImpl.java:292)
at com.ibm.ws.runtime.WsServerImpl.start(WsServerImpl.java:223)
at com.ibm.ws.runtime.WsServerImpl.main(WsServerImpl.java:686)
at com.ibm.ws.runtime.WsServer.main(WsServer.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:76)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:607)
at com.ibm.wsspi.bootstrap.WSLauncher.launchMain(WSLauncher.java:234)
at com.ibm.wsspi.bootstrap.WSLauncher.main(WSLauncher.java:96)
at com.ibm.wsspi.bootstrap.WSLauncher.run(WSLauncher.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:76)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:607)
at org.eclipse.equinox.internal.app.EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:587)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:198)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:76)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:607)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:340)
at org.eclipse.core.launcher.Main.basicRun(Main.java:282)
at org.eclipse.core.launcher.Main.run(Main.java:981)
at com.ibm.wsspi.bootstrap.WSPreLauncher.launchEclipse(WSPreLauncher.java:380)
at com.ibm.wsspi.bootstrap.WSPreLauncher.main(WSPreLauncher.java:151)

Reporter BEGIN:com.ibm.ws.jpa.management.JPAComponentImpl@bec837b3
com.ibm.ws.jpa.management.AbstractJPAComponent::CLASS_NAME:com.ibm.ws.jpa.management.AbstractJPAComponent
com.ibm.ws.jpa.management.AbstractJPAComponent::tc BEGIN:com.ibm.ejs.ras.TraceComponent@e391d426
com.ibm.ejs.ras.TraceElement::ivLevel:10


Can anyone please help me this as this issue is being observed in 2 environments, and for the rest of the environemnts it is working absolutely fine.

Hoping for a reply soon.

--Thanks


Top
 Profile  
 
 Post subject: Re: Issues with hibernate jpa 2.1 compatibility
PostPosted: Tue Feb 02, 2016 12:52 am 
Newbie

Joined: Fri Nov 06, 2015 5:06 am
Posts: 12
Hi team,

Can anyone please help me on the issue I have mentioned..

--Thanks in advance


Top
 Profile  
 
 Post subject: Re: Issues with hibernate jpa 2.1 compatibility
PostPosted: Tue Feb 02, 2016 5:33 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1518
The problem is here:

Code:
FFDC Exception:java.lang.ClassNotFoundException SourceId


Websphere cannot locate that class. Make sure that it's available on the AS classptah, or on the war/ear you are deploying.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.