Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reserved field name 'language' causes trouble. [DATAMONGO-1049] #1892

Closed
spring-projects-issues opened this issue Sep 5, 2014 · 3 comments
Closed
Assignees
Labels
type: bug A general bug

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Sep 5, 2014

Christoph Guse opened DATAMONGO-1049 and commented

With having support for full-text-search there seem to be a problem having MongoDB field names 'language'.

In a legacy project (with legacy data) there are several entities having a member variable 'language' with are using the field name 'language' in MongoDB.

This causes the exception

Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Cannot set language override on language as it is already defined on language.
	at org.springframework.data.mongodb.core.index.TextIndexDefinition$TextIndexDefinitionBuilder.withLanguageOverride(TextIndexDefinition.java:321)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$3.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:234)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$3.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:226)
	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:294)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.appendTextIndexInformation(MongoPersistentEntityIndexResolver.java:226)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.access$400(MongoPersistentEntityIndexResolver.java:56)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$3.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:256)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$3.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:226)
	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:294)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.appendTextIndexInformation(MongoPersistentEntityIndexResolver.java:226)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.access$400(MongoPersistentEntityIndexResolver.java:56)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$3.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:256)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$3.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:226)
	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:294)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.appendTextIndexInformation(MongoPersistentEntityIndexResolver.java:226)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.potentiallyCreateTextIndexDefinition(MongoPersistentEntityIndexResolver.java:205)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.resolveIndexForEntity(MongoPersistentEntityIndexResolver.java:99)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.resolveIndexForClass(MongoPersistentEntityIndexResolver.java:79)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.resolveIndexForClass(MongoPersistentEntityIndexResolver.java:56)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.checkForAndCreateIndexes(MongoPersistentEntityIndexCreator.java:128)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.checkForIndexes(MongoPersistentEntityIndexCreator.java:121)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.onApplicationEvent(MongoPersistentEntityIndexCreator.java:105)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.onApplicationEvent(MongoPersistentEntityIndexCreator.java:46)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:98)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:333)
	at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:307)
	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:181)
	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:141)
	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:67)
	at org.springframework.data.mongodb.repository.support.MongoRepositoryFactory.getEntityInformation(MongoRepositoryFactory.java:141)

In the current Implementation MongoPersistentEntityIndexResolver checks in line 233 if the persistentProperty is a language property. Each object member variable using a field name 'language' is recognized as languageProperty.

There should be an annotation like @NoLanguage to mark all member variables which have noting to do with the MongoDB full text search


Affects: 1.6 M1 (Evans), 1.6 GA (Evans)

Reference URL: http://stackoverflow.com/questions/25687121/how-to-disable-full-text-search-in-spring-data-mongodb-1-6-0-rc1

Issue Links:

  • DATAMONGO-1053 In 1.6, any field in a mapped object named "language" will fail to map if it is a type other than String
    ("is depended on by")

Referenced from: pull request #224

Backported to: 1.6.1 (Evans SR1)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Sep 9, 2014

Christoph Strobl commented

Only having a field named language should not trigger any action as long as there are not other properties within the entity having @TextIndexed.

Therefore it would be really helpful if you could provide a little more information on what you types look like or add a sample reproducing the error.

Using any of the text search features of MongoDB v2.0.2 would not work as this is something introduced in the 2.6 version

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Sep 12, 2014

Christoph Guse commented

Hi Christoph,

thanks for your reply.

One of the critical class is this one

@TypeAlias("Translation")
@Document
@XmlType(name = "translation", namespace = XmlNamespaces.DMS_NAMESPACE, propOrder = {})
@XmlAccessorType(XmlAccessType.NONE)
public class Translation implements Serializable, Comparable<Translation> {

	private static final long serialVersionUID = 5335717744539100605L;

	public static final String ATTRIBUTE_VALUE = "value";
	public static final String ATTRIBUTE_LANGUAGE = "language";
	public static final String ATTRIBUTE_DESCRIPTION = "description";

	public static final String ERROR_NO_LANGUAGE = "{error.no.language}";
	public static final String ERROR_NO_TRANSLATION_VALUE = "{error.no.translation.value}";

	@XmlJavaTypeAdapter(CDataStringAdapter.class)
	@XmlElement(name = "language")
	@Field("language")
	private String lang;

	@XmlJavaTypeAdapter(CDataStringAdapter.class)
	@XmlElement(name = "value")
	@org.springframework.data.mongodb.core.mapping.Field("value")
	private String value;

	@XmlJavaTypeAdapter(CDataStringAdapter.class)
	@XmlElement(name = "description")
	private String description;

	public Translation() {

	}

	public Translation(String label) {
		super();
		this.value = label;
	}

	/**
	 * Sets the language for the translation (key).
	 * 
	 * @param language
	 */
	public void setLang(String language) {
		this.lang = language;

	}

	/**
	 * Gets the language for the translation.
	 * 
	 * @return the language for the translation.
	 */
	@NotNull(message = ERROR_NO_LANGUAGE)
	public String getLang() {
		return lang;
	}

	/**
	 * Sets the value for the translation.
	 * 
	 * @param value
	 */
	public void setValue(String value) {

		this.value = value;

	}

	/**
	 * Gets the value for the translation.
	 * 
	 * @return the value for the translation.
	 */
	@NotNull(message = ERROR_NO_TRANSLATION_VALUE)
	public String getValue() {
		return value;
	}

	/**
	 * Sets the description for the translation.
	 * 
	 * @param description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * 
	 * @return the description for the translation
	 */
	public void setDescription(String description) {
		this.description = description;
	}
...
}

I renamed the member variable "language" to "lang" which did not help. Changing the field mapping to "lang" helped and the above mentioned exception was thrown for anoter language member variable.

I also used MongoDB v2.6 for testing purposes which did not change anything.

Searching all my sources for "@TextIndexed" did not bring any results, I do not use this annotation (maybe it is set automatically through some configuration?) In my project I do not need a full text search, so I did not activate it (at least I think so)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Sep 13, 2014

Christoph Strobl commented

Thanks Christoph Guse I think I can now nail it down. The error occurs whenever you've more than one property referring to a language property.

@Document
class A {
  @Id String id;
  @FIeld("language") String lang;
  B b;
}

class B {
  String language;
}

During Type inspection we scan for potential index structures. The language property is a special one for text index and therefore recognized - though no index creation will be triggered if there is not at least one @TextIndexed property. As you cannot define more than one language field per text index the error is thrown before even calling ensureIndex.

Long story short, we'll fix that - sorry for inconvenience and thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants