掲示板

Finder methods not being generated from service.xml [resolved]

14年前 に Dave Jerome Willis によって更新されました。

Finder methods not being generated from service.xml [resolved]

Expert 投稿: 301 参加年月日: 09/07/13 最新の投稿
When I run the build-services ant task it builds all the appropriate classes listed in my service.xml file but none of the finder methods are being generated. The exact same methods are being generated for every entity regardless of what's in the service.xml file. The only difference is that the methods reflect the name of the entity, i.e. in one named Sweetie they all say getSweetie, addSweetie, etc. but from an entity named SweetieImage they say getSweetieImage, addSweetieImage, etc. Here's an entity from my service.xml:

<entity name="SweetieMonthlyGallery" local-service="true" remote-service="true">
		<!-- PK fields -->
		<column name="SweetieMonthlyGalleryId" type="long" primary="true" />
		
		<!-- Audit fields -->
		<column name="userId" type="long" />
		<column name="companyId" type="long" />
		<column name="groupId" type="long" />
		<column name="createDate" type="Date" />
		<column name="modifiedDate" type="Date" />
		
		<!-- Other fields -->
		<column name="year" type="String" />
		<column name="month" type="String" />		

		<!-- Order -->
		<order by="desc">
			<order-column name="year" />
			<order-column name="month" />
		</order>

		<!-- Finder methods -->
		<finder name="CompanyId" return-type="Collection">
			<finder-column name="companyId" />
		</finder>
		<finder name="GroupId" return-type="Collection">
			<finder-column name="groupId" />
		</finder>
		<finder name="UserId" return-type="Collection">
			<finder-column name="userId" />
		</finder>
		<finder name="MonthYear" return-type="Collection">
			<finder-column name="month" />
			<finder-column name="year" />
		</finder>
	</entity>

It generates the class and all the appropriate SQL for the fields but no finder methods. Any ideas? Thanks.
-Dave
14年前 に Dave Willis によって更新されました。

RE: Finder methods not being generated from service.xml

Expert 投稿: 301 参加年月日: 09/07/13 最新の投稿
Bump?
thumbnail
14年前 に Amos Fong によって更新されました。

RE: Finder methods not being generated from service.xml

Liferay Legend 投稿: 2047 参加年月日: 08/10/07 最新の投稿
Hi Dave,

Was a file generated called SweetieMonthlyGalleryPersistenceImpl.java? I think the finder methods would be in there.
14年前 に Dave Willis によって更新されました。

RE: Finder methods not being generated from service.xml

Expert 投稿: 301 参加年月日: 09/07/13 最新の投稿
Yeah, that file was generated but the finder methods aren't in it. It's generating the exact same methods for every entity in my service.xml but with the names changed accordingly. It's like it's not even paying attention to the finder methods.
14年前 に Dave Willis によって更新されました。

RE: Finder methods not being generated from service.xml

Expert 投稿: 301 参加年月日: 09/07/13 最新の投稿
Still haven't been able to figure this out. I realized that I was looking at the LocalServiceUtil class and not the PersistenceImpl that Amos mentioned. I looked in there and the finder methods do actually exist there. But I shouldn't be calling PersistenceImpl from my action class, I should be calling LocalServiceUtil which means I can only call methods that exist in that class since it doesn't extend anything. Anyone have any idea what that's about?
-Dave
thumbnail
14年前 に Amos Fong によって更新されました。

RE: Finder methods not being generated from service.xml

Liferay Legend 投稿: 2047 参加年月日: 08/10/07 最新の投稿
I believe the methods in *LocalServiceUtil/Impl classes aren't auto generated so you should add your own methods in there that call the persistence methods.
14年前 に Dave Willis によって更新されました。

RE: Finder methods not being generated from service.xml

Expert 投稿: 301 参加年月日: 09/07/13 最新の投稿
Are you sure? I was pretty certain that they are auto generated. When we did this in training we didn't have to add them ourselves I don't think.
thumbnail
14年前 に Amos Fong によって更新されました。

RE: Finder methods not being generated from service.xml

Liferay Legend 投稿: 2047 参加年月日: 08/10/07 最新の投稿
Ohh I think the way it works is, you modify the LocalServiceImpl.java class and then when you run ant build-service, LocalServiceUtil.java and LocalService.java will be autogenerated.
14年前 に Dave Willis によって更新されました。

RE: Finder methods not being generated from service.xml

Expert 投稿: 301 参加年月日: 09/07/13 最新の投稿
See, I'm pretty sure that Util and Impl both are auto-generated. I could be wrong, but my recollection from the training course was that if you modified those classes your changes would be lost the next time you built services. I think you're only supposed to work with services.xml when creating entities. But clearly I'm not doing something right so I guess that could be it. I'll look into it.
thumbnail
14年前 に Jeffrey Handa によって更新されました。

RE: Finder methods not being generated from service.xml

Liferay Master 投稿: 541 参加年月日: 08/12/01 最新の投稿
Hi Dave,

When you initially define your entity in service.xml, you are defining the interface. The build-service will then build the interface and its best guess at the initial implementation. You would then add any necessary business logic to your LocalServiceImpl and then when you run the build-service task again, the interfaces will be updated to reflect the changes to your LocalServiceImpl.
thumbnail
14年前 に Amos Fong によって更新されました。

RE: Finder methods not being generated from service.xml

Liferay Legend 投稿: 2047 参加年月日: 08/10/07 最新の投稿
Ah, Jeff with the clearer explanation. Thanks Jeff!
14年前 に Dave Willis によって更新されました。

RE: Finder methods not being generated from service.xml

Expert 投稿: 301 参加年月日: 09/07/13 最新の投稿
I guess I'm still confused. I realize that you add business logic to the LocalServiceImp classes but shouldn't LocalServiceUtil already have the finder methods built, or at least stubbed out? In my entity I have several tags like this:


finder name="CompanyId" return-type="Collection"&gt;
	<finder-column name="companyId" />



But no associated methods are being generated. If you have to write these yourself, what's the point in having them in the service.xml file?
thumbnail
14年前 に Wilson Man によって更新されました。

RE: Finder methods not being generated from service.xml

Liferay Master 投稿: 581 参加年月日: 06/06/21 最新の投稿
the methods for the finders are "fleshed" out in the persistence layer only. They are not "stubbed" out in the service layer (aka :LocalService*) because you may choose to not expose them for various reasons.

One is that you may need the finder in a more complex method that you in turn expose to your caller.

Also, for each finder you defined in service.xml, the persistence layer actually creates several methods for you to make it easier. For example, it would create a finder with paginated parameters (int start, int end) etc.

So for you to define in your ServiceImpl or LocalServiceImpl gives you a higher level of control.
14年前 に Dave Willis によって更新されました。

RE: Finder methods not being generated from service.xml

Expert 投稿: 301 参加年月日: 09/07/13 最新の投稿
Oh, okay. I just didn't remember having to do that during the training session. So do I need to write them in the LocalServiceUtil class then, or LocalServiceImpl?
14年前 に Dave Willis によって更新されました。

RE: Finder methods not being generated from service.xml

Expert 投稿: 301 参加年月日: 09/07/13 最新の投稿
Wait, LocalServiceUtil doesn't extend anything. What's the proper way to access PersistenceImp? I really have no recollection of doing any of this during training...
-Dave
thumbnail
14年前 に Wilson Man によって更新されました。

RE: Finder methods not being generated from service.xml

Liferay Master 投稿: 581 参加年月日: 06/06/21 最新の投稿
you create your methods in LocalServiceImpl, and then rerun the build-service ant task. Then LocalServiceUtil should have the same methods generated. Only public non-static methods are generated.
14年前 に Dave Willis によって更新されました。

RE: Finder methods not being generated from service.xml

Expert 投稿: 301 参加年月日: 09/07/13 最新の投稿
Okay, so I put this in my LocalServiceImpl class:

public Collection findBySweetieId(long sweetieId) throws SweetieException{
	SweetieImagePersistenceImpl sipl = new SweetieImagePersistenceImpl();
	Collection images;
	
	try{
		images = sipl.findBySweetieId(sweetieId);
	}catch(Exception e){
		throw new SweetieException();
	}
	
	return images;
}


I'm not sure that I implemented it properly since I would expect PersistenceImpl to have a factory but this is the only way I could immediately see to do it and Eclipse complied it without errors. I rebuilt my services and refreshed ext but there is still no findBySweetieId method in my LocalServiceUtil class. What am I doing wrong?
14年前 に Dave Willis によって更新されました。

RE: Finder methods not being generated from service.xml

Expert 投稿: 301 参加年月日: 09/07/13 最新の投稿
Okay, it looks like when I run build-services it is actually generating the methods but for some reason Eclipse isn't aware of it. I checked and findBySweetieId(long sweetieId) does exist in the LocalServiceUtil class. So I guess it will work once I'm able to fix the problems with my portal and portlet projects and am able to deploy the portlet. So I guess I'd just like to verify whether or not the way I've written this method is the appropriate way to do it.
thumbnail
14年前 に Jeffrey Handa によって更新されました。

RE: Finder methods not being generated from service.xml

Liferay Master 投稿: 541 参加年月日: 08/12/01 最新の投稿
Hi Dave,

Yes, that's known issue with Eclipse (and possibly other IDE's). Every time you run Service Builder, you'll need to refresh the project so it syncs with the file system. If you're using Package Explorer in Eclipse, you'll also need to manually add the Service folder as a source folder.

The process you've described in the previous post is correct. Implement your custom logic in LocalServiceImpl, run Service Builder to regenerate the interface. Refresh the project in Eclipse to see the changes to the interface.
14年前 に Dave Willis によって更新されました。

RE: Finder methods not being generated from service.xml

Expert 投稿: 301 参加年月日: 09/07/13 最新の投稿
Yeah, I knew Eclipse wouldn't automatically detect changes to the file system but I did refresh it, and I just did it again, and Eclipse still isn't aware of those new methods. Even thought I can clearly see them in the class file. It's weird. I even shut Eclipse down and reloaded it.

So there isn't a factory for PersistenceImpl classes and just instantiating a new instance is the correct way to do it?
Thanks!
Dave
thumbnail
14年前 に Wilson Man によって更新されました。

RE: Finder methods not being generated from service.xml

Liferay Master 投稿: 581 参加年月日: 06/06/21 最新の投稿
you don't need to instantiate the PersistenceImpl directly. you should already have a local reference of it injected via Spring. so you should be able to just call <entity_name>Persistence
14年前 に Dave Willis によって更新されました。

RE: Finder methods not being generated from service.xml

Expert 投稿: 301 参加年月日: 09/07/13 最新の投稿
I feel like I'm having a huge brain fart here and this should be easy to fix but it's not coming to me. I changed my code to the following:

s2gs = SweetieToGalleryPersistence.findBySweetieMonthlyGalleryId(id);


This doesn't work because it's a non-static method and I'm trying to call it statically but I just can't think of how else to do it. Help?
thumbnail
14年前 に Wilson Man によって更新されました。

RE: Finder methods not being generated from service.xml

Liferay Master 投稿: 581 参加年月日: 06/06/21 最新の投稿
do you mean your method in your LocalServiceImpl is static? (it shouldn't be static)
14年前 に Dave Willis によって更新されました。

RE: Finder methods not being generated from service.xml

Expert 投稿: 301 参加年月日: 09/07/13 最新の投稿
Yeah. I guess I'm confused. I thought you were telling me to call it statically, like <entity_name>Persistence.findByWhatever(). Is that not what you meant?
thumbnail
14年前 に Wilson Man によって更新されました。

RE: Finder methods not being generated from service.xml

Liferay Master 投稿: 581 参加年月日: 06/06/21 最新の投稿
Wilson Man:
you create your methods in LocalServiceImpl, and then rerun the build-service ant task. Then LocalServiceUtil should have the same methods generated. Only public non-static methods are generated.


I said it should be non-static =)
Only public AND non-static methods in your LocalServiceImpl will be generated in LocalServiceUtil.

So you just need to make your methods non-static to fix the problem. =)
14年前 に Dave Willis によって更新されました。

RE: Finder methods not being generated from service.xml

Expert 投稿: 301 参加年月日: 09/07/13 最新の投稿
I'm still confused. I'm sorry. The method I'm writing is public and non-static but the method in the Persistence class is where I'm having trouble. Originally had I this:

public List<sweetietogallery> findBySweetieMonthlyGalleryId(long id) throws SweetieToGalleryException{
	SweetieToGalleryPersistenceImpl s2gpi = new SweetieToGalleryPersistenceImpl();
	List<sweetietogallery> s2gs;
	
	try{
		s2gs = s2gpi.findBySweetieMonthlyGalleryId(id);
	}catch(Exception e){
		throw new SweetieToGalleryException();
	}
	
	return s2gs;
}
</sweetietogallery></sweetietogallery>


But then I thought you said that I didn't need to instantiate a new object because Spring made available to me the class SweetieToGalleryPersistence so I changed my code to this:

public List<sweetietogallery> findBySweetieMonthlyGalleryId(long id) throws SweetieToGalleryException{
	List<sweetietogallery> s2gs;
	
	try{
		s2gs = SweetieToGalleryPersistence.findBySweetieMonthlyGalleryId(id);
	}catch(Exception e){
		throw new SweetieToGalleryException();
	}
	
	return s2gs;
}
</sweetietogallery></sweetietogallery>


But it would seem that both of these are wrong. Sorry I'm so slow and thank you for your patience and assistance.
thumbnail
14年前 に Wilson Man によって更新されました。

RE: Finder methods not being generated from service.xml

Liferay Master 投稿: 581 参加年月日: 06/06/21 最新の投稿
hey Dave,

not a problem.

I assume the class you're writing these methods is SweetieToGalleryLocalServiceImpl? If so, you should already have a sweetieToGalleryPersistence member that's declared from the BaseImpl which your LocalServiceImpl is extending.

Notice that sweetieToGalleryPersistence starts with a lowercase s.
14年前 に Dave Willis によって更新されました。

RE: Finder methods not being generated from service.xml

Expert 投稿: 301 参加年月日: 09/07/13 最新の投稿
Okay. That makes a lot more sense to me now. I had just failed to notice that you were referencing an object rather than a class. Thanks!

So my only remaining question about this topic is why does Eclipse think these methods do not exist? I've built my services and I can open LocalServiceUtil and see the methods that have been generated from the ones I wrote in LocalServiceImpl but in my Action class when I call SweetieToGalleryLocalServiceUtil.findByMonthlyGalleryId(id), or any other method I wrote, Eclipse underlines it and says that the method is undefined. I have refreshed all my projects but it made no difference.
14年前 に Dave Willis によって更新されました。

RE: Finder methods not being generated from service.xml

Expert 投稿: 301 参加年月日: 09/07/13 最新の投稿
Nevermind. Another brain fart. I had to redeploy ext and remove and then add back ext-service.jar to my portlet. I'm good now. Thanks for the help!
13年前 に Matthew Dickson によって更新されました。

RE: Finder methods not being generated from service.xml

New Member 投稿: 4 参加年月日: 09/11/29 最新の投稿
[indent]Dave,

I'm having the same sort of issues. What do you mean exactly about manually adding the 'service' folder as a source folder. I can't even seem to see the MyPortletLocalServiceUtil compilied class.

Matt

[/indent]
thumbnail
14年前 に Amos Fong によって更新されました。

RE: Finder methods not being generated from service.xml

Liferay Legend 投稿: 2047 参加年月日: 08/10/07 最新の投稿
Doesn't your LocalServiceImpl class extend a LocalServiceBaseImpl class that should have bean references to the persistence classes.

So you should be able to just call

sweetieImagePersistence.findBySweetieId()