This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 177234 - Named queries can only be defined on an Entity or MappedSuperclass class
Summary: Named queries can only be defined on an Entity or MappedSuperclass class
Status: RESOLVED WORKSFORME
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Assignee: Sergey Petrov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-19 11:34 UTC by billshannon
Modified: 2014-01-13 11:59 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description billshannon 2009-11-19 11:34:46 UTC
I have this code (fragment of the complete file):

@NamedQueries({
@NamedQuery(name = "deleteAll", query = "DELETE FROM Wine"),
@NamedQuery(name = "findByType",
    query = "SELECT w FROM Wine w WHERE w.type = :type AND w.bottles > 0 " +
        "ORDER BY w.winery, w.vintage, w.wine"),
@NamedQuery(name = "findAllByType",
    query = "SELECT w FROM Wine w WHERE w.type = :type " +
        "ORDER BY w.winery, w.vintage, w.wine"),
@NamedQuery(name = "findTypes",
    query = "SELECT DISTINCT w.type FROM Wine w")
})

@Entity
@IdClass(Wine.WineKey.class)

public class Wine implements Comparable<Wine>, Cloneable {


On that last line above the editor shows an error marker and the popup says

  Named queries can only be defined on an Entity or MappedSuperclass class.

  Only Entity or MappedSuperclass can use IdClass.

  Surround with ... 


The first and second errors seem wrong, my class clearly *is* an Entity.

I have no idea what it wants to surround with what.

I'm using NetBeans 6.8beta.
Comment 1 Sergey Petrov 2009-11-19 12:23:42 UTC
can you provide complete/compilable code for your entity as attachment and reopen the issue?

I just tried to put your code in my entity and don't see the issue, but have other items like "should implement serializable" etc.
may be some new lines make sense or wrong imports etc to reproduce the issue.
Comment 2 billshannon 2009-11-19 12:29:44 UTC
Code provided offline.
Comment 3 Sergey Petrov 2009-11-20 03:47:03 UTC
not sure if it was fixed later or some steps are missed. still can't reproduce the issue. on ubuntu+1.6.14.
just opened provided project and see no reported issue I see only "serializable" warning and "entity should be top level class" error.
can you try to rename your nb home temporary and open the project with fresh one, and try to open the project with one of the latest builds?
Comment 4 billshannon 2009-11-20 13:11:02 UTC
I'm sorry, you want me to try yet a newer version of NetBeans?

I get so tired of downloading the latest version, reporting a bug,
and then being told to download an even newer version.

Have *you* tried to reproduce the bug with NetBeans 6.8beta?
If it doesn't reproduce for you using the same version I'm using,
then obviously something else is wrong.  Let's figure out what
the difference is between our environments first.
Comment 5 Sergey Petrov 2009-11-20 15:54:52 UTC
ok, will try with beta to see if it was reproducible on my system and may be was fixed later.
Comment 6 Sergey Petrov 2010-03-31 15:05:43 UTC
finally I have some time but can't download beta now, not sure what may happened in this case, I saw the same issue on another system once, and never on my, it looks like something may be broken with nb installation/initialization/home dir etc in this case, if the issue will be reproducible message.log from nb home may help as it may contain some exception and or additional information(like enabled modules, classpath etc), feel free to reopen the issue if it's still valid.
Comment 7 rainshowers 2011-05-16 18:21:24 UTC
I was experiencing this with two classes that were created with the "New, Entity classes from database" option.  The problem went away after deleting my var/cache/index folder.  v6.9.1
Comment 8 gaithal 2013-01-15 07:27:58 UTC
I too had the same problem in v7.2.1. It went away after re-installing NetBeans.
Comment 9 dobri 2013-08-27 14:45:07 UTC
I resolved it, by deleting 
C:\Documents and Settings\%username%\My Documents\Application Data\NetBeans\7.3.1\var\filehistory folder.
Comment 10 Sergey Petrov 2013-08-27 17:09:30 UTC
may mean, parsing fails sometimes to actual data, but existence of workaround is good
Comment 11 billshannon 2013-08-27 19:17:26 UTC
Sounds like someone needs to figure out why these cache/index/whatever files
get out of sync with reality.

Maybe NetBeans needs a "consistency checker" for these files, and a button
to rebuild the files and fix any errors?
Comment 12 dobri 2013-08-28 11:05:07 UTC
I must admit, that in some cases, deleting "~\Application Data\NetBeans\7.3.1\var\filehistory" doesn't work.
Today I had once more this problem, so I deleted entire "~\Application Data\NetBeans" folder, so now I don't have this "Named queries can only be defined on an Entity or MappedSuperclass class" issue.
This issues escalated maybe few days ago, and everything new I've done since than, is that the project I work with, the most of the day I work on my work laptop, and those three times, in order to continue to do at home, I exported project as a zip, and then, I worked at home. So the next day, I exported a project from my home computer, and imported on laptop at work.
Maybe this made this problems by broking files and settings...