Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Sedro
Dec 31, 2008

Cryolite posted:

Is it a good idea to put configuration files in the same directory as my jar files so I can change them without needing to rebuild the jar?

I don't have much experience with Java and mostly come from a .NET background. In .NET my logging .xml files and other configuration files sat alongside my executables and I could change them to tweak settings or change logging levels without needing to rebuild the executable. These configuration files weren't embedded resources.

In Java it seems the path of least resistance is to put these kinds of files into a resources directory so they're packaged in the jar. Is there an easy way to supply/change API keys to my app or change logging config without redeploying the jar? It seems like having these kinds of config files sitting in the same directory as jar files isn't a common practice in the Java world.

How do I best do configuration? Is there a common pattern so that I can keep files like logback.xml, twitterkeys.conf, etc. in the same directory as my jar instead of locked away inside the jar?

Java tools generally look for files on the classpath, using code like getClass().getResourceAsStream("/logback.xml")

You set up your classpath when you start the application. Your classpath probably looks something like this:
pre:
java -cp "a.jar;b.jar;c.jar" entrypoint.jar
In this case, Java will search the root of each jar for "logback.xml"

You can add arbitrary directories to the classpath, and Java will search those too:
pre:
# add the current directory to the classpath
java -cp ".;a.jar;b.jar;c.jar" entrypoint.jar

# add the "conf" directory to the classpath and put all our jars in "lib"
java -cp "lib/a.jar;lib/b.jar;lib/c.jar;conf" entrypoint.jar
java -cp "lib/*;conf" entrypoint.jar
In this case, Java will find your file at "conf/logback.xml"

It's also common to configure directories with Java system properties or environment variables.

Adbot
ADBOT LOVES YOU

Sindai
Jan 24, 2007
i want to achieve immortality through not dying
It's also worth noting that jar files are just zip files with a different extension, so you can open them in any compressed file tool and edit their contents, you don't need to "rebuild" the jar file.

But obviously if it's something you expect end users to edit external files are much more convenient.

Gravity Pike
Feb 8, 2009

I find this discussion incredibly bland and disinteresting.

Cryolite posted:

Is it a good idea to put configuration files in the same directory as my jar files so I can change them without needing to rebuild the jar?

I don't have much experience with Java and mostly come from a .NET background. In .NET my logging .xml files and other configuration files sat alongside my executables and I could change them to tweak settings or change logging levels without needing to rebuild the executable. These configuration files weren't embedded resources.

In Java it seems the path of least resistance is to put these kinds of files into a resources directory so they're packaged in the jar. Is there an easy way to supply/change API keys to my app or change logging config without redeploying the jar? It seems like having these kinds of config files sitting in the same directory as jar files isn't a common practice in the Java world.

How do I best do configuration? Is there a common pattern so that I can keep files like logback.xml, twitterkeys.conf, etc. in the same directory as my jar instead of locked away inside the jar?

It's not a bad idea - this is how we deploy our services at my company. We've got Chef configured to dump a log4j2.xml and config.json in the same directory as our servicename.jar (standalone web services), and our common service library looks in 1) The current directory, then 2) the classpath for configuration. We use maven as a build tool, so we've got these same files in src/test/resources for our service-level tests, but with different configuration, and these are never compiled into our artifacts. Our philosophy is that, if we don't have the chef-generated configuration correct, we'd rather the service doesn't work at all than have the service work incorrectly by loading configuration that was meant for a different environment.

The pattern is probably going to be different if you're not doing SaaS, though.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
edit: I succeeded close enough

Malloc Voidstar fucked around with this message at 17:52 on Apr 9, 2016

ulmont
Sep 15, 2010

IF I EVER MISS VOTING IN AN ELECTION (EVEN AMERICAN IDOL) ,OR HAVE UNPAID PARKING TICKETS, PLEASE TAKE AWAY MY FRANCHISE

Malloc Voidstar posted:

edit: I succeeded close enough

I was going to say that you have to derive a font and font metrics, and then get the rectangle for the string in the context of your graphics object.

code:
        g2d.setRenderingHint (RenderingHints.KEY_ANTIALIASING,   RenderingHints.VALUE_ANTIALIAS_ON); // g2d is a Graphics2D Object from the BufferedImage
        g2d.setPaint(Color.BLACK);
        g2d.setStroke(new BasicStroke(1.0f));
        Font f = g2d.getFont().deriveFont(15f);
        g2d.setFont(f);
        FontMetrics fm = g2d.getFontMetrics(f);
        Rectangle2D rect = fm.getStringBounds(legend.getTitle(), g2d);
        // now you know the bounds to figure out where it goes...

Boz0r
Sep 7, 2006
The Rocketship in action.
In the new project I've been assigned to, there's a search function which involves piecing a huge SQL query together in a 600 line function, based on the different search parameters. This seems like a really complicated way of doing it. What's the smart way?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Boz0r posted:

In the new project I've been assigned to, there's a search function which involves piecing a huge SQL query together in a 600 line function, based on the different search parameters. This seems like a really complicated way of doing it. What's the smart way?

I'm going to assume that actually having such a large query is essential to the app's function. The basic idea is to abstract each part of the search out into its own thing. For example, you might write a quick SearchParameter interface:

code:
public interface SearchParameter {
  public void setText(String text);

  public String getAsSqlWhereClause();
}
And subclass it for each different type of parameter that tells you how to express the appropriate SQL clause for that type of parameter.

So then you express your queries as a list of SearchParameters, and iterate over those clauses to turn them into SQL whenever you need to actually execute a query. Your "advanced search page" logic might map each text box to the relevant SearchParameter type, while the parser for your regular search box might look for attribute:value pairs in the search query and turn those into SearchParameters of the appropriate type.

This decouples everything nicely and makes it easy to update later - if your tables shuffle around a bit, you just need to change the appropriate SearchParameter to filter on the new column, instead of updating the N different places that you actually construct a search query. You can also do cool things like convert a search query into something other than SQL - perhaps you're experimenting with a high-performance or distributed database that doesn't use SQL. Or perhaps you want to display a friendly name to stick in the page title based on what exactly is being searched for. Or maybe you want to turn an arbitrary query back into something the user could type into the text box, so you can teach your users that they can just type "category:foo" into the quick search instead of going to the advanced search every time. Eventually you may want to remix it into the visitor pattern (or some other form of double-dispatch if your language supports it) if you find yourself writing the exact same code for multiple different parameter types, but that's not really necessary to start with.

Boz0r
Sep 7, 2006
The Rocketship in action.
That's exactly the kind of thing I was looking for. Is it called something specific, and do you have some links to examples?

TheresaJayne
Jul 1, 2011

Boz0r posted:

That's exactly the kind of thing I was looking for. Is it called something specific, and do you have some links to examples?

you could do some form of prepared statement

denzelcurrypower
Jan 28, 2011
Can anyone recommend some resources for client/server socket programming in Java? I currently have an application designed to retrieve/write data to the database from the client application. I'd like to have the client application communicate with a server and the server will query the database and return results to the client.

I've been using this as a resource - https://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html. But it's very basic and I'm running into a few issues. How can I have the server always listening for requests and respond by running the appropriate code to query the database, and then return the results to the client? Based on the Oracle example it seems I need to create a protocol. However, the example is just returning one string and I'm confused how to send varying amounts of data between client/server. How does the server know what to expect, when the data has stopped being sent, and assign it to variables? Thanks for any info.

Carbon dioxide
Oct 9, 2012

For a college course I'm writing a paper about Apache Maven.

Now, the internet tells me that Gradle is better in almost every way. Okay, that is good to know. But it would be really very useful if I could also write down some advantages of Maven over Gradle (perhaps Maven works better for certain types of projects?) so it seems like I'm doing a fair comparison and then conclude Gradle is the better tool anyway.

So, can anyone tell me reasons to use Maven instead of Gradle, and/or link to resources talking about that?

TheresaJayne
Jul 1, 2011

Carbon dioxide posted:

For a college course I'm writing a paper about Apache Maven.

Now, the internet tells me that Gradle is better in almost every way. Okay, that is good to know. But it would be really very useful if I could also write down some advantages of Maven over Gradle (perhaps Maven works better for certain types of projects?) so it seems like I'm doing a fair comparison and then conclude Gradle is the better tool anyway.

So, can anyone tell me reasons to use Maven instead of Gradle, and/or link to resources talking about that?

Gradle is faster than Maven, I wish we didnt need to use Maven at work,

Our Maven Build has 320 projects and takes 90 minutes to build and test.
The same project under Gradle is 312 projects and 15 minutes to build and test.

The extra projects in Maven are the bundle poms and the master poms that we have in the master gradle build.gradle as tasks.

ExcessBLarg!
Sep 1, 2001

Carbon dioxide posted:

So, can anyone tell me reasons to use Maven instead of Gradle, and/or link to resources talking about that?
Maven is very mature and third-party plugin support is top-notch. That wasn't the case when Gradle 1.0 came out in 2012. It's probably better, but there's still complaints that third-party support for Gradle isn't as good. As a general argument though, don't underestimate the weight of established third-part support when choosing or otherwise continuing to use a legacy platform. Thus, there's pretty good arguments for using Gradle with new projects, but if you're already using Maven and don't have issues with it, there are fewer compelling reasons to switch.

Some folks might prefer Maven's declaratory XML approach vs. Gradle's interpreted DSL. Usually the DSL is going to be more concise and, often, easier to read. But, if for some reason you wanted to write a third-party tool to parse and do something with your build configurations, it's going to be easier to independently parse an XML-based schema then it is to tie into Groovy and such.

JewKiller 3000
Nov 28, 2006

by Lowtax

Carbon dioxide posted:

For a college course I'm writing a paper about Apache Maven.

Now, the internet tells me that Gradle is better in almost every way. Okay, that is good to know. But it would be really very useful if I could also write down some advantages of Maven over Gradle (perhaps Maven works better for certain types of projects?) so it seems like I'm doing a fair comparison and then conclude Gradle is the better tool anyway.

So, can anyone tell me reasons to use Maven instead of Gradle, and/or link to resources talking about that?

Maven is the industry standard tool, Gradle is some alternative poo poo that Groovy idiots came up with because they're special snowflakes who can't handle XML.

smackfu
Jun 7, 2004

TheresaJayne posted:

Gradle is faster than Maven, I wish we didnt need to use Maven at work,

Our Maven Build has 320 projects and takes 90 minutes to build and test.
The same project under Gradle is 312 projects and 15 minutes to build and test.

The extra projects in Maven are the bundle poms and the master poms that we have in the master gradle build.gradle as tasks.

Why would Gradle be faster than Maven? Aren't they both just running other programs (compiler, test runners) which is most of the build / test time?

Sedro
Dec 31, 2008

JewKiller 3000 posted:

Maven is the industry standard tool, Gradle is some alternative poo poo that Groovy idiots came up with because they're special snowflakes who can't handle XML.

I'll write my build in a real programming language, thanks.

I thought nobody used gradle, but it's almost as popular as maven on github (pom.xml vs build.gradle)


smackfu posted:

Why would Gradle be faster than Maven? Aren't they both just running other programs (compiler, test runners) which is most of the build / test time?

For one, maven doesn't run in parallel unless you use an experimental flag which is not enabled by default.

Gravity Pike
Feb 8, 2009

I find this discussion incredibly bland and disinteresting.

Ornithology posted:

Can anyone recommend some resources for client/server socket programming in Java? I currently have an application designed to retrieve/write data to the database from the client application. I'd like to have the client application communicate with a server and the server will query the database and return results to the client.

I've been using this as a resource - https://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html. But it's very basic and I'm running into a few issues. How can I have the server always listening for requests and respond by running the appropriate code to query the database, and then return the results to the client? Based on the Oracle example it seems I need to create a protocol. However, the example is just returning one string and I'm confused how to send varying amounts of data between client/server. How does the server know what to expect, when the data has stopped being sent, and assign it to variables? Thanks for any info.

Do you have a compelling reason to use bare sockets instead of a higher-level abstraction? If you can imagine your client POST-ing a JSON-formatted request to a webserver, and then getting a JSON response back, it might be simpler to leverage Jersey or Spring to set up a server that handles HTTP requests.

Nude
Nov 16, 2014

I have no idea what I'm doing.
Dipping my toes in Java right now (using Eclipse if that matters), and my first project is a simple image editor. What I have so far is: I can load an image, rotate it and move it which is nice. But a thought occurred to me to have it so someone could "upload" their own image to my Java application.

How would I go about doing this? I tried searching the web before hand but couldn't find anything about uploading/reading new files when the application is already built. Any help is appreciated.

pigdog
Apr 23, 2004

by Smythe

smackfu posted:

Why would Gradle be faster than Maven? Aren't they both just running other programs (compiler, test runners) which is most of the build / test time?

Gradle is a background process, Maven starts up and works from scratch. Gradle should also be better at figuring out which modules have changed, and recompile only the changed parts in subsequent builds. If I remember correctly, then some versions ago the incremental build flag in Maven used to do exactly the opposite of what it was supposed to.

Paul MaudDib
May 3, 2006

TEAM NVIDIA:
FORUM POLICE
Quick question: I am trying to set up Spring Security mappings so that if an authenticated user goes to "/" then they see "/main" but a non-authenticated user would see "/login". I'm using the automatic form-login functionality.

I set up a simple controller which does this, but "redirect:/login" as a destination doesn't work, presumably because that's not a real HTML page that exists in the project (it's in the Spring Security JARfile presumably). This seems like pretty basic functionality, there's got to be a way to do this.

Paul MaudDib
May 3, 2006

TEAM NVIDIA:
FORUM POLICE

Gravity Pike posted:

Do you have a compelling reason to use bare sockets instead of a higher-level abstraction? If you can imagine your client POST-ing a JSON-formatted request to a webserver, and then getting a JSON response back, it might be simpler to leverage Jersey or Spring to set up a server that handles HTTP requests.

Yeah, I don't understand why you'd be re-writing a web server here. Even servlets can be used to send back JSON, just send "text/json" as the content-type and dump a stringified JsonObject into the response body.

Greatbacon
Apr 9, 2012

by Pragmatica

Nude posted:

Dipping my toes in Java right now (using Eclipse if that matters), and my first project is a simple image editor. What I have so far is: I can load an image, rotate it and move it which is nice. But a thought occurred to me to have it so someone could "upload" their own image to my Java application.

How would I go about doing this? I tried searching the web before hand but couldn't find anything about uploading/reading new files when the application is already built. Any help is appreciated.

The simplest way is probably a command-line argument. This lets you pass in a filename/location at the command line like
code:
java yourProgram.jar "C:\\filename.jpg"
Sorry if that's not what you're looking for, it's sort of hard to tell how complex your program is from the description.

Cerepol
Dec 2, 2011


Alright if anyone has used JPA/Hibernate before I'm having an issue with a OneToMany bidirectional relationship with a Composite Primary Key

In the one class I want a OneToMany relationship with I have this.
code:
@Entity @IdClass(HandID.class)
@Table(name="hand") 
public class HandData {

	@Id
	@ManyToOne
	@JoinColumn(name="playerID")
	private PlayerData player;
	
	@Id
	@ManyToOne(optional=false)
	@JoinColumn(name="gameID", nullable=false)
	private GameData game;
The IdClass is just a simple class with the attributes and serialID


In the other I have this.
code:
@Entity
@Table(name="game")
public class GameData {

	@SequenceGenerator(name="gameSEQ", sequenceName="gameID_SEQ")
	@Id
	@GeneratedValue(generator="gameSEQ")
	private long gameID;

	@OneToMany(mappedBy="game")
	private List<HandData> hand;
Does anyone have any clues why if I remove @Id from the 'game' attribute in HandData it works flawlessly?

Ideally I would prefer to have that security. But as the Database is not being auto generated by hibernate the primary key enforcement doesn't need to happen on this end.
(Or is there something wrong with JPA not realizing that 'game' is a part of the primary key?)

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

Nude posted:

Dipping my toes in Java right now (using Eclipse if that matters), and my first project is a simple image editor. What I have so far is: I can load an image, rotate it and move it which is nice. But a thought occurred to me to have it so someone could "upload" their own image to my Java application.

How would I go about doing this? I tried searching the web before hand but couldn't find anything about uploading/reading new files when the application is already built. Any help is appreciated.

This is an incredibly broad question. Do you mean simply to "open" the file in your application? "upload" implies a web context. Is your program a java applet or designed to run in a webpage? How are users accessing the program. What is the context?

If its simply adding a new image to the program as a desktop app at runtime, there's a few ways to go about it. The common way is to give the user a file browse dialog, let them select the file, and then access the file through disk I/O.

Greatbacon posted:

The simplest way is probably a command-line argument. This lets you pass in a filename/location at the command line like
code:
java yourProgram.jar "C:\\filename.jpg"
Sorry if that's not what you're looking for, it's sort of hard to tell how complex your program is from the description.

This is the easiest and fastest way to program, and the upside is that people can drag a picture over the application in order to open the picture in the program. But its also limited, in that they'll have to close and open the program to change pictures.

If its a web context, then you have a whole other can of worms to look into, for how to upload the file over the 'net and then how to access that file, but its still perfectly do-able. What exactly are you asking?

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

Cerepol posted:

Alright if anyone has used JPA/Hibernate before I'm having an issue with a OneToMany bidirectional relationship with a Composite Primary Key

In the one class I want a OneToMany relationship with I have this.
code:
@Entity @IdClass(HandID.class)
@Table(name="hand") 
public class HandData {

	@Id
	@ManyToOne
	@JoinColumn(name="playerID")
	private PlayerData player;
	
	@Id
	@ManyToOne(optional=false)
	@JoinColumn(name="gameID", nullable=false)
	private GameData game;
The IdClass is just a simple class with the attributes and serialID


In the other I have this.
code:
@Entity
@Table(name="game")
public class GameData {

	@SequenceGenerator(name="gameSEQ", sequenceName="gameID_SEQ")
	@Id
	@GeneratedValue(generator="gameSEQ")
	private long gameID;

	@OneToMany(mappedBy="game")
	private List<HandData> hand;
Does anyone have any clues why if I remove @Id from the 'game' attribute in HandData it works flawlessly?

Ideally I would prefer to have that security. But as the Database is not being auto generated by hibernate the primary key enforcement doesn't need to happen on this end.
(Or is there something wrong with JPA not realizing that 'game' is a part of the primary key?)

Why do you have two @Id tags? If your primary key is complex, then you probably need the @generatedvalue annotation to tell it how to process the multiple @id tags with a strategy. Does the default handle multiple IDs gracefully?

Nude
Nov 16, 2014

I have no idea what I'm doing.

Zaphod42 posted:

This is an incredibly broad question. Do you mean simply to "open" the file in your application? "upload" implies a web context. Is your program a java applet or designed to run in a webpage? How are users accessing the program. What is the context?

If its simply adding a new image to the program as a desktop app at runtime, there's a few ways to go about it. The common way is to give the user a file browse dialog, let them select the file, and then access the file through disk I/O.


This is the easiest and fastest way to program, and the upside is that people can drag a picture over the application in order to open the picture in the program. But its also limited, in that they'll have to close and open the program to change pictures.

If its a web context, then you have a whole other can of worms to look into, for how to upload the file over the 'net and then how to access that file, but its still perfectly do-able. What exactly are you asking?

Hey thanks guys for the help, I meant open instead of upload, sorry for being so vague. The problem was mainly I didn't know the key terms to search on google, once I searched Java I/O (which I now know means input/output) I was able to get the docs that I needed to pull this off.

Cerepol
Dec 2, 2011


Zaphod42 posted:

Why do you have two @Id tags? If your primary key is complex, then you probably need the @generatedvalue annotation to tell it how to process the multiple @id tags with a strategy. Does the default handle multiple IDs gracefully?

Nah, the @IdClass annotation lets it know what the meaning of their being 2 are. And neither needs to be generated as one is a foreign key and the other will be given by a controller.

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

Cerepol posted:

Nah, the @IdClass annotation lets it know what the meaning of their being 2 are. And neither needs to be generated as one is a foreign key and the other will be given by a controller.

Hm, well not sure the exact reasoning but with multiple @Id tags not working and removing one working, that's almost assuredly the culprit. Something is confusing the annotations and its not handling it properly.

Cerepol
Dec 2, 2011


Zaphod42 posted:

Hm, well not sure the exact reasoning but with multiple @Id tags not working and removing one working, that's almost assuredly the culprit. Something is confusing the annotations and its not handling it properly.

Well I still have 2 @Id tags in the file instead of the 3 where it doesn't work. So as far I as I can tell it's an interaction between a IdClass and the OneToMany reference. Unfortunately it seems rather hard to google and rather rare apparently.

Cryolite
Oct 2, 2006
sodium aluminum fluoride
How much is typical memory usage for a Spring app? I tried playing around with JHipster, a yeoman generator that generates Spring Boot apps, and so far I've seen memory usage hover around 600MB. Is this normal? It's really slick, but for hosting something on a cheap DigitalOcean box I'm afraid it's a relative memory hog.

Sedro
Dec 31, 2008

Cryolite posted:

How much is typical memory usage for a Spring app? I tried playing around with JHipster, a yeoman generator that generates Spring Boot apps, and so far I've seen memory usage hover around 600MB. Is this normal? It's really slick, but for hosting something on a cheap DigitalOcean box I'm afraid it's a relative memory hog.

What command line is it running? There might be a startup script setting -Xms512m or similar

Cryolite
Oct 2, 2006
sodium aluminum fluoride
I was running it from Intellij which wasn't setting any of those parameters. When I ran it with -Xmx300m it seemed to obey the max. Interestingly, when I run it from Intellij it pegs one of my CPU cores at 100% even when I'm not doing anything, and the app isn't processing requests that I know of. When I run it using "mvn spring-boot:run" it uses 0% CPU when I'm not doing anything, though the memory usage is still very high - sometimes as high as 800-1000MB.

Gravity Pike
Feb 8, 2009

I find this discussion incredibly bland and disinteresting.

Cryolite posted:

How much is typical memory usage for a Spring app? I tried playing around with JHipster, a yeoman generator that generates Spring Boot apps, and so far I've seen memory usage hover around 600MB. Is this normal? It's really slick, but for hosting something on a cheap DigitalOcean box I'm afraid it's a relative memory hog.

Our Jersey webapps tend to want around 500MB, yeah. :(

Cryolite
Oct 2, 2006
sodium aluminum fluoride
What's the danger of doing -Xmx256m or something like that in this situation then? Way more time spent doing garbage collection?

smackfu
Jun 7, 2004

Yeah, I mean, it's Spring Boot, the whole idea is that it should work without config in as many cases as possible. The memory settings were probably chosen fairly arbitrarily but high so that most apps work without getting an out-of-memory error.

Sindai
Jan 24, 2007
i want to achieve immortality through not dying

Cryolite posted:

What's the danger of doing -Xmx256m or something like that in this situation then? Way more time spent doing garbage collection?
If you get near the max, yes. If you need more than the max your threads start getting out of memory errors.

If you want to see all the information you can handle about what your application's doing with memory, there's a visual memory/cpu profiler that comes with the JDK: jvisualvm.exe

Sindai fucked around with this message at 18:02 on Apr 18, 2016

weas
Jul 22, 2007

Tougher than the
toughest tough guy

Cerepol posted:

Alright if anyone has used JPA/Hibernate before I'm having an issue with a OneToMany bidirectional relationship with a Composite Primary Key

In the one class I want a OneToMany relationship with I have this.
code:
@Entity @IdClass(HandID.class)
@Table(name="hand") 
public class HandData {

	@Id
	@ManyToOne
	@JoinColumn(name="playerID")
	private PlayerData player;
	
	@Id
	@ManyToOne(optional=false)
	@JoinColumn(name="gameID", nullable=false)
	private GameData game;
The IdClass is just a simple class with the attributes and serialID


In the other I have this.
code:
@Entity
@Table(name="game")
public class GameData {

	@SequenceGenerator(name="gameSEQ", sequenceName="gameID_SEQ")
	@Id
	@GeneratedValue(generator="gameSEQ")
	private long gameID;

	@OneToMany(mappedBy="game")
	private List<HandData> hand;
Does anyone have any clues why if I remove @Id from the 'game' attribute in HandData it works flawlessly?

Ideally I would prefer to have that security. But as the Database is not being auto generated by hibernate the primary key enforcement doesn't need to happen on this end.
(Or is there something wrong with JPA not realizing that 'game' is a part of the primary key?)

Did you try using an EmbeddedId? I've done something like this before which looks similar to your use case:

code:
@Entity
@Table(name="hand") 
public class HandData {

	@EmbeddedId
	private Id id = new Id();
	
	@ManyToOne
	@JoinColumn(name="playerID")
	private PlayerData player;
	
	@ManyToOne(optional=false)
	@JoinColumn(name="gameID", nullable=false)
	private GameData game;
	
	@Embeddable
	public static class Id implements Serializable {
		private static final long serialVersionUID = 1L;

		@Column(name = "playerID")
		private long playerID;

		@Column(name = "gameID")
		private long gameID;
		
		...getters/setters/etc
	}

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
Once again I'm fighting with loving logging and loving log levels, this time with jetty. (mvn jetty:run)

How the gently caress do I make it so that my call to LOG.debug("loving Christ I'm tired of this poo poo"); actually gets logged. Info, warn, error and fatal levels work fine.

edit: LOG is an instange of org.apache.commons.logging.Log

Wheany fucked around with this message at 08:37 on Apr 21, 2016

FateFree
Nov 14, 2003

Usually there is some sort of configuration file depending on the underlying log implementation where you have to set the root level to DEBUG and not INFO where its at now.

Adbot
ADBOT LOVES YOU

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.
I haven't used commons-logging but it looks like the same design as log4j, like FateFree said there's just a config file somewhere you need to modify.

Its useful because it lets you set lots of custom error levels, so you could get full DEBUG level from mydomain.* classes, but then set it to ERROR level only for org.apache.* classes or whatever.

Its very useful for quickly fine-tuning your logging messages, but can be a pain to get set up at first if you're not seeing the message you want.

If you're seeing error messages but not debug, its gotta just be the config.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply