I have the following (simplified) Hibernate entities:
@Entity
@Table(name = "package")
public class Package {
protected Content content;
@OneToOne(cascade = {javax.persistence.CascadeType.ALL})
@JoinColumn(name = "content_id")
@Fetch(value = FetchMode.JOIN)
public Content getContent() {
return content;
}
public void setContent(Content content) {
this.content = content;
}
}
@Entity
@Table(name = "content")
public class Content {
private Set<Content> subContents = new HashSet<Content>();
private ArchivalInformationPackage parentPackage;
@OneToMany(fetch = FetchType.EAGER)
@JoinTable(name = "subcontents", joinColumns = {@JoinColumn(name = "content_id")}, inverseJoinColumns = {@JoinColumn(name = "elt")})
@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE, org.hibernate.annotations.CascadeType.REPLICATE})
@Fetch(value = FetchMode.SUBSELECT)
public Set<Content> getSubContents() {
return subContents;
}
public void setSubContents(Set<Content> subContents) {
this.subContents = subContents;
}
@ManyToOne(cascade = {CascadeType.ALL})
@JoinColumn(name = "parent_package_id")
public Package getParentPackage() {
return parentPackage;
}
public void setParentPackage(Package parentPackage) {
this.parentPackage = parentPackage;
}
}
So there is one Package, which has one "top" Content. The top Content links back to the Package, with cascade set to ALL. The top Content may have many "sub" Contents, and each sub-Content may have many sub-Contents of its own. Each sub-Content has a parent Package, which may or may not be the same Package as the top Content (ie a many-to-one relationship for Content to Package).
The relationships are required to be ManyToOne (Package to Content) and ManyToMany (Content to sub-Contents) but for the case I am currently testing each sub-Content only relates to one Package or Content.
The problem is that when I delete a Package and flush the session, I get a Hibernate error stating that I'm violating a foreign key constraint on table subcontents, with a particular content_id still referenced from table subcontents.
I've tried specifically (recursively) deleting the Contents before deleting the Package but I get the same error.
Is there a reason why this entity tree is not being deleted properly?
EDIT: After reading answers/comments I realised that a Content cannot have multiple Packages, and a sub-Content cannot have multiple parent-Contents, so I have modified the annotations from ManyToOne and ManyToMany to OneToOne and OneToMany. Unfortunately that did not fix the problem.
I have also added the bi-directional link from Content back to the parent Package which I left out of the simplified code.
I'd like to apply a Median Filter to a bi-level image and output a bi-level image. The JAI median filter seems to output an RGB image, which I'm having trouble downconverting back to bi-level.
Currently I can't even get the image back into gray color-space, my code looks like this:
BufferedImage src; // contains a bi-level image
ParameterBlock pb = new ParameterBlock();
pb.addSource(src);
pb.add(MedianFilterDescriptor.MEDIAN_MASK_SQUARE);
pb.add(3);
RenderedOp result = JAI.create("MedianFilter", pb);
ParameterBlock pb2 = new ParameterBlock();
pb2.addSource(result);
pb2.add(new double[][]{{0.33, 0.34, 0.33, 0}});
RenderedOp grayResult = JAI.create("BandCombine", pb2);
BufferedImage foo = grayResult.getAsBufferedImage();
This code hangs on the grayResult line and appears not to return. I assume that I'll eventually need to call the "Binarize" operation in JAI.
Edit: Actually, the code appears to be stalling once I call getAsBufferedImage(), but returns nearly instantly when the second operation ("BandCombine") is removed.
Is there a better way to keep the Median Filtering in the source color domain? If not, how do I downconvert back to binary?
Is it possible to store something like the following using only one table? Right now, what hibernate will do is create two tables, one for Families and one for people. I would like for the familymembers object to be serialized into the column in the database.
@Entity(name = "family")
class Family{
private final List<Person> familyMembers;
}
class Person{
String firstName, lastName;
int age;
}
Hey there Stackoverflow,
I got a doubt regarding pre-selecting(setSelectedIndex(index)) an item in a ListBox, Im using Spring + GWT.
I got a dialog that contains a painel, this panel has a flexpanel, in which I've put a couple ListBox, this are filled up with data from my database.
But this painel is for updates of an entity in my database, thus I wanted it to pre-select the current properties for this items, alowing the user to change at will.
I do the filling up in the update method of the widget.
I tried setting the selectedItem in the update method, but it gives me an null error.
I've searched a few places and it seems that the listbox are only filled at the exact moment of the display. Thus pre-selecting would be impossible.
I thought about some event, that is fired when the page is displayed.
onLoad() doesnt work..
Anyone have something to help me out in here?
Thx in advance,
Rodrigo Dellacqua
does not compile. Indeed: even in 1.5, this api, getIntent(), is already listed as deprecated.
The error message I get complains that getIntent() does not return a String, but setCurrentTab() expects a string.
If I guess and change the line to read:
"tabHost.setCurrentTab(1); // was setCurrentTab(getIntent())",
then it compiles, builds, but does not run. I get the "stopped unexpectedly" error message from the emulator. I cannot even get Log.d to output, so it seems that it stops 'unexpectedly' very early.
So the first and main question is: what is the correct fix to "tabHost.setCurrentTab(getIntent())" in the final line of OnCreate() in http://developer.android.com/resources/tutorials/views/hello-tabwidget.html?
The second and simpler question is: did I guess right in replacing 'mTabHost' with tabHost in the one place where that occurs?
Hi.
I'm playing with a GWT/GAE project which will have three different "pages", although it is not really pages in a GWT sense. The top views (one for each page) will have completely different layouts, but some of the widgets will be shared.
One of the pages is the main page which is loaded by the default url (http://www.site.com), but the other two needs additional URL information to differentiate the page type. They also need a name parameter, (like http://www.site.com/project/project-name. There are at least two solutions to this that I'm aware of.
Use GWT history mechanism and let page type and parameters (such as project name) be part of the history token.
Use servlets with url-mapping patterns (like /project/*)
The first choice might seem obvious at first, but it has several drawbacks. First, a user should be able to easily remember and type URL directly to a project. It is hard to produce a human friendly URL with history tokens. Second, I'm using gwt-presenter and this approach would mean that we need to support subplaces in one token, which I'd rather avoid. Third, a user will typically stay at one page, so it makes more sense that the page information is part of the "static" URL.
Using servlets solves all these problems, but also creates other ones.
So my first questions is, what is the best solution here?
If I would go for the servlet solution, new questions pop up.
It might make sense to split the GWT app into three separate modules, each with an entry point. Each servlet that is mapped to a certain page would then simply forward the request to the GWT module that handles that page. Since a user typically stays at one page, the browser only needs to load the js for that page. Based on what I've read, this solution is not really recommended.
I could also stick with one module, but then GWT needs to find out which page it should display. It could either query the server or parse the URL itself.
If I stick with one GWT module, I need to keep the page information stored on server side. Naturally I thought about sessions, but I'm not sure if its a good idea to mix page information with user data. A session usually lives between user login and logout, but in this case it would need different behavior. Would it be bad practise to handle this via sessions?
The one GWT module + servlet solution also leads to another problem. If a user goes from a project page to the main page, how will GWT know that this has happened? The app will not be reloaded, so it will be treated as a simple state change. It seems rather ineffecient to have to check page info for every state change.
Anyone care to guide me out of the foggy darkness that surrounds me? :-)
I'd like to implement declarative security with Spring/AOP and annotations.
As you see in the next code sample I have the Restricted Annotations with the paramter "allowedRoles" for defining who is allowed to execute an adviced method.
@Restricted(allowedRoles="jira-administrators")
public void setPassword(...) throws UserMgmtException {
// set password code
...
}
Now, the problem is that in my Advice I have no access to the defined Annotations:
public Object checkPermission(ProceedingJoinPoint pjp) throws Throwable {
Signature signature = pjp.getSignature();
System.out.println("Allowed:" + rolesAllowedForJoinPoint(pjp));
...
}
private Restricted rolesAllowedForJoinPoint(ProceedingJoinPoint thisJoinPoint)
{
MethodSignature methodSignature = (MethodSignature) thisJoinPoint.getSignature();
Method targetMethod = methodSignature.getMethod();
return targetMethod.getAnnotation(Restricted.class);
}
The method above always returns null (there are no annotations found at all).
Is there a simple solution to this?
I read something about using the AspectJ agent but I would prefer not to use this agent.
With signpost 1.2:
String authUrl = provider.retrieveRequestToken( consumer, callbackUrl );
Netflix API response:
<status>
<status_code>
400
</status_code>
<message>
oauth_consumer_key is missing
</message>
</status>
I see how to craft the URL manually via the netflix documentation, but this seems to contradict other services which use OAuth authentication. Who's incorrect, here? Is there a way to get signpost to work with Netflix, aside from contributing to the signpost source? :P
Hi
I have this array A = <3,2,9,0,7,5,4,8,6,1> and I want to write all its worst partitions are these correct?thanks
a1 = <0,2,9,3,7,5,4,8,6,1>
a2 = <1,9,3,7,5,4,8,6,2>
a3 = <2,3,7,5,4,8,6,9>
a4 = <3,7,5,4,8,6,9>
a5 = <4,5,7,8,6,9>
a6 = <5,7,8,6,9>
a7 = <6,8,7,9>
a8 = <7,8,9>
a9 = <8,9>
a10 = <9>
i write a method and when i add some insignificant code it works faster,
like these :
array[1]=array[1];
array[0]=array[0];
array[3]=array[3];
array[2]=array[2];
i use double t=System.currentTimeMillis(); at first to record the time.
then call the method
and use System.out.println(System.currentTimeMillis()-t); in the end.
when i delete the code (array[1]=array[1];...) the cost time is 1035.0 ms,but if i add these code,
the cost time become 898.0ms.
here is my method and my code. PS:this method is use for the game 2048, exp: {2,2,2,2} trans to {0,0,4,4}
static void toRight2(int[] array){
if (array[2]==array[3] ) {
array[3]=array[2]*2;
if (array[0]==array[1]) {
array[2]=array[1]*2;
array[0]=0;
array[1]=0;
}else {
array[2]=array[1];
array[1]=array[0];
array[0]=0;
}
} else{
if (array[0]==array[1]) {
array[1]=array[1]*2;
array[0]=0;
array[3]=array[3];
array[2]=array[2];
}else {
array[1]=array[1];//delete this cost more time
array[0]=array[0];//delete this cost more time
array[3]=array[3];//delete this cost more time
array[2]=array[2];//delete this cost more time
}
}
}
public static void main(String[] args) {
double t=System.currentTimeMillis();
int[] array={1,2,3,3};
for (int j = 2; j <400*1000000; j++) {
toRight2(array);
}
System.out.println(System.currentTimeMillis()-t);
}
What is the relation between web.xml and jboss-web.xml? Seems like:
Jboss-web.xml
specifies the security domain (which can be found in login-config.xml)
web.xml
specifies what the security level is
I don't understand what happens when jboss-web.xml specifies a weak security domain. Ie: one that cannot do what web.xml specifies. What happens then?
I've been searching for while now and I can't find a simple example of how to capture a webcam stream with FMJ. Are there any tutorials or examples available which could help me?
I have entities that required versioning support and from time to time, i will need to retrieve old version of the entity . should i just use
options available
1. http://stackoverflow.com/questions/762405/database-data-versioning
2. jboss envers (can this be used on any web server,tomcat,jetty, appengine) ?
3. any similar library like jboss that ease to do versioning?
I used HTTPComponents to implement a custom web server that access SQLite database. Requests are sent via TCP/IP and I am using REST concepts. By the way my frontend is HTML/jQuery. I know it will be a lot easier if I'll just create a servlet but I am restricted to just using apache http server.
I really don't get good performance in using HTTP Components.
Any suggestions please.
Thanks in advance.
Hi There!
I have a design problem .
My application has multiple J2EE components ,In simple terms one acts as a service provider(Non UI) and others are consumers(UI webapp) .
The consumer gets the configuration data from the service provider(this basically reads the data from DB) during the start up and stores it in the Cache.
The cache gets refreshed after periodic time to reflect any changes done at the database.
The Problem
Apart from the cache refresh ,I also want to notify the consumers when someone changes the DB . that configuration has been changed please reload it.
What notification mechanism's can I use to achieve this.
Thanks!
Pratik
My DAO detaches and then caches certain objects, and it may retrieve them with different fetch groups. Depending on which fetch group was used to retrieve the object, certain fields of that object may be available, or not. I would like to be able to test whether a given field on that object was loaded or not, but I can't simply check whether the field is null because that results in a "JDODetachedFieldAccessException" which demands that I either not access the field or add detach the field first.
I could always catch that exception, but that doesn't smell right. So, does anyone know whether its possible to check if the field was detached?
Hi
I have a special requirement for one of my applications where I need the servers nounce (Handshaker.srv_random) when verifying the client certificate.
Yet JSSEs X509TrustManager only passes me the certificate, no other information of the handshake.
I have located the place, where checkClientTrusted is called (inside ServerHandshaker) and it would be easy to extend it to also allow some X509CustomTrustManager to be called with all required information. Yet this would require me to recompile JSSE...
I also found jsse sources in openjdk.
Now for my questions:
What is the easiest way to compile jsse from openjdk?
Can the resulting jsse.jar be used as a replacement for the (original) sun jre as a replacement for the included jsse.jar?
Is there another (more standard compliant) way to archive what I am trying to do? I did not find a hook to use my own handshaker...
Regards,
Steffen
Hi All !
I have hashmap and its keys are like "folder/1.txt,folder/2.txt,folder/3.txt" and value has these text files data.
Now i am stucked. I want to sort this list. But it does not let me do it :(
Here is my hashmap data type:
HashMap<String, ArrayList<String>>
following function work good but it is for arraylist not for hashmap.
Collections.sort(values, Collections.reverseOrder());
I also tried MapTree but it also didn't work, or may be I couldn't make it work. I used
following steps to sort the code with maptree
HashMap testMap = new HashMap();
Map sortedMap = new TreeMap(testMap);
any other way to do it??
I have one doubt as my keys are (folder/1.txt, folder/2.txt ) may be that's why?
It seems like EclipseLink has been chosen by sun as the reference implementation of JPA 2.0, nevertheless I see lots of people continue to use hibernate...
I have no experience with none of them, so I wonder which one should I choose for a new project...
I'd like to know the pros / cons of each one...
thanks a lot
ps: btw, and this is part of the answer, there are 3636 questions on stackoverflow about hibernate, and only 68 about eclipselink...
And its not '&'
Im using the SAXParser object do parse the actual XML.
This is normally done by passing a URL to the XMLReader.Parse method.
Because my XML is coming from a POST request to a webservice, I am saving that result as a String and then employing StringReader / InputSource to feed this string back to the XMLReader.Parse method.
However, something strange is happening at the 2001st character of the XMLstring.
The 'characters' method of the document handler is being called TWICE in between the startElement and endElement methods, effectively breaking my string (in this case a project title) into two pieces. Because I am instantiating objects in my characters method, I am getting two objects instead of one.
This line, about 2000 chars into the string fires 'characters' two times, breaking between "Lower" and "Level"
<title>SUMC-BOOKSTORE, LOWER LEVEL RENOVATIONS</title>
When I bypass the StringReader / InputSource workaround and feed a flat XML file to XMLReader.Parse, it works absolutely fine.
Something about StringReader and or InputSource is somehow screwing this up.
Here is my method that takes and XML string and parses is through the SAXParser.
public void parseXML(String XMLstring) {
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
xr.setContentHandler(this);
// Something is happening in the StringReader or InputSource
// That cuts the XML element in half at the 2001 character mark.
StringReader sr = new StringReader(XMLstring);
InputSource is = new InputSource(sr);
xr.parse(is);
} catch (IOException e) {
Log.e("CMS1", e.toString());
} catch (SAXException e) {
Log.e("CMS2", e.toString());
} catch (ParserConfigurationException e) {
Log.e("CMS3", e.toString());
}
}
I would greatly appreciate any ideas on how to not have 'characters' firing off twice when I get to this point in the XML String.
Or, show me how to use a POST request and still pass off the URL to the Parse function.
THANK YOU.
In their real life, are Object Oriented Programmers more forgetting than Structured Language Programmers. I personally feel that way being a an Object Oriented Programmer.
Basically I'm wondering how I'm able to do what I've written in the topic. I've looked through many tutorials on AsyncTask but I can't get it to work. I have a little form (EditText) that will take what the user inputs there and make it to a url query for the application to lookup and then display the results.
What I think would seem to work is something like this: In my main activity i have a string called responseBody. Then the user clicks on the search button it will go to my search function and from there call the GrabUrl method with the url which will start the asyncdata and when that process is finished the onPostExecute method will use the function activity.this.setResponseBody(content).
This is what my code looks like simpliefied with the most important parts (I think).
public class activity extends Activity {
private String responseBody;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initControls();
}
public void initControls() {
fieldSearch = (EditText) findViewById(R.id.EditText01);
buttonSearch = (Button)findViewById(R.id.Button01);
buttonSearch.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ search();
}});
}
public void grabURL(String url) {
new GrabURL().execute(url);
}
private class GrabURL extends AsyncTask<String, Void, String> {
private final HttpClient client = new DefaultHttpClient();
private String content;
private boolean error = false;
private ProgressDialog dialog = new ProgressDialog(activity.this);
protected void onPreExecute() {
dialog.setMessage("Getting your data... Please wait...");
dialog.show();
}
protected String doInBackground(String... urls) {
try {
HttpGet httpget = new HttpGet(urls[0]);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
content = client.execute(httpget, responseHandler);
} catch (ClientProtocolException e) {
error = true;
cancel(true);
} catch (IOException e) {
error = true;
cancel(true);
}
return content;
}
protected void onPostExecute(String content) {
dialog.dismiss();
if (error) {
Toast toast = Toast.makeText(activity.this, getString(R.string.offline), Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP, 0, 75);
toast.show();
} else {
activity.this.setResponseBody(content);
}
}
}
public void search() {
String query = fieldSearch.getText().toString();
String url = "http://example.com/example.php?query=" + query; //this is just an example url, I have a "real" url in my application but for privacy reasons I've replaced it
grabURL(url); // the method that will start the asynctask
processData(responseBody); // process the responseBody and display stuff on the ui-thread with the data that I would like to get from the asyntask but doesn't obviously
}